Tomcat 8 Examples: Missing Configuration Step

旧巷老猫 提交于 2019-12-12 10:02:38

问题


I'm trying to set up the "Echo" websocket example on Tomcat 8. I believe I am missing the step where you tell tomcat about the websocket classes.

Here's what I have done:

  • Created a new dynamic web project in Eclipse, added maven, and linked tomcat 8 runtimes
  • Copied EchoAnotation.java, EchoEndpoint.java, ExamplesConfig.java, and echo.xhtml into the project.
  • Started the app.

When I start the app, I can navigate to the echo.xhtml file, but no matter what url I enter, I can't seem to figure out how to get to web sockets--I always get 404. Putting breakpoints in the constructors, it looks like the websocket classes aren't being loaded.

Normally you set up the class configuration in web.xml or some other framework config, but I couldn't find a matching configuration in the examples web.xml on the Tomcat8 SVN (or any other xml.)

Any insight on how this is done?

Thanks!


Source Code

EchoAnotation.java, EchoEndpoint.java, ExamplesConfig.java Location:

http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/ http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo

Echo.xhtml location:

http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/websocket/

Example web.xml location:

http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/

My web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"> 
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

回答1:


Figured it out. Newest versions of war-based webapps do component scans automatically. Mine was not, because I had included this:

Do not include if you have tomcat included!

    <dependency>
        <groupId>javax.websocket</groupId>
        <artifactId>javax.websocket-api</artifactId>
        <version>1.0</version>
    </dependency>

Reference on Websocket endpoints:

https://tyrus.java.net/documentation/1.3.3/index/deployment.html



来源:https://stackoverflow.com/questions/20723818/tomcat-8-examples-missing-configuration-step

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!