2015-09-09 88 views
1

我試圖在Tomcat 7上運行Spring Boot應用程序。從我的理解來看,它應該與servlet 3.0規範兼容。Spring Boot Servlet API Version

在我的依賴,我標誌着Tomcat作爲提供:

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-tomcat</artifactId> 
    <scope>provided</scope> <!-- Mark as provided so it doesn't interfere when we deploy in container --> 
</dependency> 

編輯:我已經添加了財產<tomcat.version>7.0.59</tomcat.version>

但我仍然無法啓動tomcat吧。我得到這個錯誤:

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
at org.apache.tomcat.websocket.server.WsServerContainer.(WsServerContainer.java:147)
at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131)
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:47)

這是因爲它顯然需要servlet規範3.1。

我錯過了什麼嗎?

回答

1

問題是,spring-boot還在spring-boot-starter-tomcat上配置了websocket支持,這是spring-boot-starter-web提供的。而根據Apache的,你必須,如果你想web套接字和Tomcat 7 這裏使用Java 7:http://tomcat.apache.org/whichversion.html

無論是使用Java 7編譯或排除的WebSocket支持

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-web</artifactId> 
    <exclusions> 
     <exclusion> 
      <groupId>org.apache.tomcat.embed</groupId> 
      <artifactId>tomcat-embed-websocket</artifactId> 
     </exclusion> 
    </exclusions> 
</dependency>