2017-09-03 36 views
2
. ____   _   __ _ _ 
    /\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \ 
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 
    \\/ ___)| |_)| | | | | || (_| | )))) 
    ' |____| .__|_| |_|_| |_\__, |//// 
    =========|_|==============|___/=/_/_/_/ 
    :: Spring Boot ::  (v1.5.6.RELEASE) 


2017-09-03 16:43:53.881 INFO 6584 --- [   main] c.n.SpringBootMvcExampleApplication  : Starting SpringBootMvcExampleApplication on lenovo-PC with PID 6584 (C:\Users\lenovo\Documents\workspace-sts-3.8.4.RELEASE\SpringBootMVCExample\target\classes started by lenovo in C:\Users\lenovo\Documents\workspace-sts-3.8.4.RELEASE\SpringBootMVCExample) 
2017-09-03 16:43:53.896 INFO 6584 --- [   main] c.n.SpringBootMvcExampleApplication  : No active profile set, falling back to default profiles: default 
2017-09-03 16:43:54.218 INFO 6584 --- [   main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]6e38921c: startup date [Sun Sep 03 16:43:54 IST 2017]; root of context hierarchy 
2017-09-03 16:43:56.213 INFO 6584 --- [   main] o.s.j.e.a.AnnotationMBeanExporter  : Registering beans for JMX exposure on startup 2017-09-03 16:43:56.294 INFO 6584 --- [   main] c.n.SpringBootMvcExampleApplication  : Started SpringBootMvcExampleApplication in 3.284 seconds (JVM running for 3.931) 
2017-09-03 16:43:56.297 INFO 6584 --- [  Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]6e38921c: startup date [Sun Sep 03 16:43:54 IST 2017]; root of context hierarchy 
2017-09-03 16:43:56.304 INFO 6584 --- [  Thread-3] o.s.j.e.a.AnnotationMBeanExporter  : Unregistering JMX-exposed beans on shutdown 
+2

請分享你的主要方法,你使用的是maven嗎?加上「 org.springframework.boot 彈簧引導啓動的Web 」 – IddoE

回答

1

請在pom.xml中添加下面的依賴項。

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-web</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-tomcat</artifactId> 
    <scope>provided</scope> 
</dependency> 

有時因爲maven中的jar衝突,spring啓動會自動關閉。所以請分享pom.xml如果問題仍然存在,即使添加上述依賴關係。

+0

標記'彈簧引導起動tomcat'爲'provided'建設將要部署戰爭時,只需要到外部容器。目前還不清楚這是否是這種情況 –

+0

沒有應用程序服務器,Web應用程序將無法啓動,因爲它需要servlet容器來啓動應用程序。 spring-boot-starter-tomcat依賴將充當嵌入式tomcat服務器。所以請包括這一點,然後再試一次。 –

0

我面對的同樣的問題,我發現我沒有告訴Spring有關要使用的服務器。通過添加下面的maven依賴關係,它對我有用。

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-rest</artifactId> 
    </dependency> 

後來我調查,發現上述神器內的pom.xml(彈簧引導啓動數據休息)本身引用下面的Maven構件,這指示Spring來添加嵌入式服務器,並使用它同時運行當前擁有此pom.xml的應用程序。

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-annotations</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-databind</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-rest-webmvc</artifactId> 
    </dependency> 

有趣的是,當你的神器(彈簧引導啓動的Web)的POM文件走得更遠,你會看到它的其他產物爲Tomcat服務器引用。下面是行家神器,你會在pom.xml找到(彈簧引導起動網)

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-tomcat</artifactId> 
    </dependency> 

注意:由於我的應用程序是使用基於REST控制器,所以我需要休息與JSON支持。所以下面的Maven依賴關係適合我。

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-rest</artifactId> 
    </dependency> 

但是那些只想要服務器集成,可以使用下面的依賴關係,它必須工作。

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
相關問題