2017-05-03 132 views
0

我在CourseApiApp.java文件下面的代碼:春天引導應用程序Tomcat服務器沒有運行

package io.myapp.hellospringboot; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 

@SpringBootApplication 
public class CourseApiApp { 

    public static void main(String[] args) { 

     SpringApplication.run(CourseApiApp.class, args); 

    } 

} 

當我按下播放按鈕,我看到下面的控制檯消息:

main] i.a.hellospringboot.CourseApiApp   : Starting CourseApiApp on johndoe-MacBook-Pro.local with PID 22730 (/Users/johndoe/Documents/workspace-sts-3.8.4.RELEASE/com.myapp.hello-spring-boot/target/classes started by john doe in /Users/johndoe/Documents/workspace-sts-3.8.4.RELEASE/com.myapp.hello-spring-boot) 
2017-05-02 21:28:29.454 INFO 22730 --- [   main] i.a.hellospringboot.CourseApiApp   : No active profile set, falling back to default profiles: default 
2017-05-02 21:28:29.552 INFO 22730 --- [   main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]5427c60c: startup date [Tue May 02 21:28:29 CDT 2017]; root of context hierarchy 
2017-05-02 21:28:30.838 INFO 22730 --- [   main] o.s.j.e.a.AnnotationMBeanExporter  : Registering beans for JMX exposure on startup 
2017-05-02 21:28:30.917 INFO 22730 --- [   main] i.a.hellospringboot.CourseApiApp   : Started CourseApiApp in 2.122 seconds (JVM running for 2.614) 
2017-05-02 21:28:30.919 INFO 22730 --- [  Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]5427c60c: startup date [Tue May 02 21:28:29 CDT 2017]; root of context hierarchy 
2017-05-02 21:28:30.920 INFO 22730 --- [  Thread-2] o.s.j.e.a.AnnotationMBeanExporter  : Unregistering JMX-exposed beans on shutdown 

UPDATE :這裏是pom.xml文件:

<parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.2.RELEASE</version> 
    </parent> 

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

    </dependencies> 

    <properties> 
     <java.version>1.8</java.version> 
    </properties> 

而且我GreetingController.java文件:

import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RestController; 

@RestController 
public class GreetingController { 

    @RequestMapping("/hello/{name}") 
     String hello(@PathVariable String name) { 
     return "Hello, " + name + "!"; 
     } 

} 
+0

它看起來像錯誤的'ApplicationContext'類型正在採摘。你的日誌顯示'AnnotationConfigApplicationContext',它應該是'AnnotationConfigEmbeddedWebApplicationContext'。這或者意味着你的類路徑是錯誤的(沒有Tomcat),或者你有一個禁用Web支持的屬性集。 「mvn dependency:tree」的輸出是什麼?如果使用'--debug'參數運行會發生什麼情況。 –

+0

我正在使用Spring Tool Suite編輯器運行所有這些。 –

回答

4

根本原因是maven緩存中損壞的jar。刪除~/.m2/repository解決了這個問題。

另一種選擇會一直運行mvn dependency:purge-local-repository

2

請刪除.m2目錄庫中的文件。主要從以下位置刪除文件: C:\ Users {UserName} .m2 \ repository \ org \ apache

通過更新POM文件再次構建應用程序並解決問題。

0

您必須添加一個依賴於文件的pom.xml:

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-web</artifactId> 
</dependency> 
+0

他已經有這種依賴 –

相關問題