This can happen if you have not registered the JAX-RS servlet implementation in your web.xml
. Jersey requires the following configuration:
<servlet> <servlet-name>jersey</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.example.service</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>jersey</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
The initialization parameter com.sun.jersey.config.property.packages
should point to the package where all your services are located. However, your code snippet is missing a package
declaration. I'm not sure if this is omitted for brevity or not, but classes without packaging are not visible to classes that themselves are in the package (for example, the Tomcat and Jersey models themselves). The above web.xml
example assumes that you have
package com.example.service;
in your webservice classes. Correct or modify it accordingly.
Please note that the URL pattern /*
means that ALL requests will be submitted through Jersey. If you need to deploy other servlets, JSPs, or static content in the same webapp, you can specify a more specific URL pattern. For instance.
<url-pattern>/rest/*</url-pattern>
You will need to change the URL of your request http: // localhost / test_server / rest / hello .
source share