2017-02-17 159 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中)。