2017-02-17 180 views
0

我正在尝试学习弹簧启动执行器。我有一个简单的基本应用程序,通过主要方法运行。它没有tomcat或任何东西。它只有一个类,如下用于独立弹簧应用的弹簧启动执行器

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> 

我试图查看应用程序健康的信息,我已经在应用程序配置的下方。性能

management.port=8091 
management.address=127.0.0.1 
management.security.enabled=false 
endpoints.shutdown.enabled=true 
info.app.name=Startup Dashboard 
info.app.version=2.0-ALPHA 
logging.file=dashboard.log 

试图链接:http://localhost:8091/info 它从来没有得到解决。

是否无法为独立应用配置执行器?

+0

我认为你正在试验Spring引导,请使用这种方法开始在这个下面的链接。 http://stackoverflow.com/questions/39245732/java-lang-noclassdeffounderror-org-springframework-core-env-configurableenviron/39246493#39246493 –

回答

0

看起来您的应用程序不是Spring Boot应用程序。它需要。

1

你的应用程序还不是Spring Boot App。

必须至少使用@SpringBootApplication才能将应用程序转换为一个应用程序。

@SpringBootApplication 
public class BootadminMsAlphaApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(BootadminMsAlphaApplication.class, args); 
    } 
} 

就是这样一个最简单的例子。

如果没有这样的话,classpath中的spring-boot依赖并没有被要求去做其神奇的事情来让你的应用程序更加智能化。全功能于一身的注释带来了弹簧启动的auto-configuration,为应用程序配置了很多好东西,包括执行器(如果在classpath中)。