Spring 独立弹簧应用的弹簧启动执行器
我正在努力学习弹簧靴执行器。我有一个简单的基本应用程序,它通过main方法运行。它没有tomcat或任何东西。它只有一个类,如下所示Spring 独立弹簧应用的弹簧启动执行器,spring,spring-boot,spring-boot-actuator,Spring,Spring Boot,Spring Boot Actuator,我正在努力学习弹簧靴执行器。我有一个简单的基本应用程序,它通过main方法运行。它没有tomcat或任何东西。它只有一个类,如下所示 public class StartUp { public static void main(String... args) throws InterruptedException { ConfigurableApplicationContext ctx = SpringApplication.run(StartUp.class,
public class StartUp {
public static void main(String... args) throws InterruptedException {
ConfigurableApplicationContext ctx = SpringApplication.run(StartUp.class,
args);
StartUp mainObj = ctx.getBean(StartUp.class);
mainObj.init();
System.out.println("Application exited");
}
public void init() throws InterruptedException {
System.out.println("inside init method");
Thread.sleep(10 * 60 * 1000);
System.out.println("outside init method");
}
}
我已在pom中配置弹簧执行器,如下所示:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<!-- [3] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
尝试url时:
它永远不会得到解决
无法为独立应用程序配置执行器吗?看起来您的应用程序不是Spring引导应用程序。它必须是。您的应用程序还不是Spring Boot应用程序 您必须至少使用
@SpringBootApplication
将一个应用程序转换为一个应用程序
@SpringBootApplication
public class BootadminMsAlphaApplication {
public static void main(String[] args) {
SpringApplication.run(BootadminMsAlphaApplication.class, args);
}
}
这是一个最简单的例子
没有这一点,类路径中的spring引导依赖项就不会被要求做一些神奇的事情来让应用程序变得智能。一体式注释将spring boot的
自动配置
发挥作用,它为应用程序配置了很多好东西,包括执行器(如果在类路径中)。我认为您正在试用spring boot,请在下面的链接中使用这种方法开始。
@SpringBootApplication
public class BootadminMsAlphaApplication {
public static void main(String[] args) {
SpringApplication.run(BootadminMsAlphaApplication.class, args);
}
}