【发布时间】:2017-05-07 07:21:03
【问题描述】:
我有一个在 Tomcat 7.0.43 上运行的 Struts2 Web 应用程序,它使用 Rest 和 Convention 插件来映射所有请求。 Struts 尝试自己映射所有请求。
JSR 356 使用注释定义服务器端点,例如
@ServerEndpoint(value = "/websocket/chat")
现在当浏览器尝试连接到ws:/127.0.0.1:8080/websocket/chat 时,请求失败,因为 Struts 映射器拦截了请求。
我可以在 XML 文件中指定什么,以便请求到达正确的位置吗?
编辑:
按照建议,我添加了
<constant name="struts.action.excludePattern" value="/websocket.*?" />
到我的 Struts 配置,之后 URL /websocket/chat 开始出现 404 错误。
后来才知道需要配置一个ServerApplicationConfig的实现。之后,websocket 开始正常工作,但我的应用程序的其余部分无法加载并出现错误:
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
这是我的课:
public class Socket implements ServerApplicationConfig {
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> scanned) {
Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();
return result;
}
@Override
public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {
Set<Class<?>> results = new HashSet<Class<?>>();
for (Class<?> clazz : scanned) {
results.add(clazz);
}
return results;
}
}
我怎样才能让所有的东西在 Harmony 中协同工作?
注意:我正在使用 Struts Spring 插件进行 Spring Security 的依赖注入。
【问题讨论】:
-
分区问题将帮助您更快地获得答案。正如您发现的那样,您可以防止 struts 在当前没有 struts2/websocket 集成之后尝试对某些 url 采取行动。这两种技术都是面向前端的(服务器上的最前端层)并且几乎没有交互。但是将两者结合成一个问题会减少听众。让事情协调工作的答案是在服务层开发业务逻辑,s2 和 ws 都会使用。
-
我也面临这个问题@Manu你有什么解决办法吗?如果你有,请告诉我。提前致谢。
标签: java spring struts2 websocket tomcat7