配置和想法:我有maven 3.3,eclipse mars,tomcat v8,并且想先部署一个简单的helloworld servlet然后我自己的代码来测试它。
我已经尝试了几天来做这个,我甚至无法进入apache主页,现在只是将其配置正确所以我在管理器webapp中看到我的Web服务。然而,它给了我一个helloworld的404状态,这不是我期望的。
所以我想知道接下来应该尝试什么。我有代码,我看到它部署在tomcat中,tomcat正在工作,但没有任何rest / servlet相关工作,它只是404状态。
我主要通过这两种路径组合来访问:
http://localhost:8080/connectedCar/
http://localhost:8080/connectedCar/rest/helloworld
POM:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.17.1</version>
</dependency>
</dependencies>
的web.xml:
<servlet>
<servlet-name>connectedCar</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>pruebaCC.connectedCar</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>connectedCar</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
tomcat用户:
<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users>
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui"/>
</tomcat-users>
Setting.xml的:
<server>
<id>tomcatserver</id>
<username>admin</username>
<password>admin</password>
</server>
答案 0 :(得分:1)
请将Jersey参数更改为泽西1的com.sun.jersey.config.property.packages。您使用的那个适用于泽西岛2.
另外,请查看最小泽西1设置ServletContainer class not found Exception
的答案答案 1 :(得分:1)
访问网络资源的实际网址格式为
http://<host>:<port>/<web_context_path>/<url_pattern>/<web_services_path>