下面的教程帮助我启动了一个spring引导应用程序,并且运行得非常快:https://spring.io/guides/gs/messaging-stomp-websocket/
但是现在我不得不尝试生成一个war文件并将其部署到我的tomcat7应用服务器上。
我按照说明创建了一个可部署的war文件,但这是行不通的。我在日志中没有看到任何错误,但当我浏览到http://localhost:8080时,我也没有看到我的示例应用程序。
下面是生成war文件的步骤:
1)修改pom.xml,将打包更改为war,并按规定标记spring starter-websocket。
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>
</dependencies>2)修改Application.java以覆盖SpringBootServletInitializer配置方法。
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}3)然后我跑了
mvn清洁包装
并部署生成的war文件,但当我浏览到http://localhost:8080/时,我只会得到默认的Tomcat欢迎页面。
我还尝试通过添加以下contextPath来更改应用程序application.properties:
server.contextPath=/websocketclient
server.port=8082但这不能解决问题。
发布于 2015-07-25 13:40:50
我开始工作了,我在用Tomcat 8。
看看我这里的代码:https://github.com/pauldeng/gs-messaging-stomp-websocket
相应地读取和编辑pom文件,并运行mvn包来创建指定的包。
发布于 2015-03-09 12:44:05
部署的应用程序war需要被称为ROOT.war,否则您必须配置server.xml。
其次,您应该打开websockets的NIO连接器(参见server.xml和http://tomcat.apache.org/tomcat-7.0-doc/web-socket-howto.html )
发布于 2015-03-09 12:45:47
我在我的pom.xml中犯了一个错误,提供的作用域不应该添加到spring初学者-websocket伪件中。但是,您应该在提供的范围内添加spring启动器-tomcat伪制品。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>
</dependencies>我还必须修改我的javascript,以联系websocket,它现在在/gs-messaging 0.1.0下面。
var socket = new SockJS('/gs-messaging-stomp-websocket-0.1.0/hello');https://stackoverflow.com/questions/28940369
复制相似问题