spring - CXF Rest with Maven and tomcat -
i try first rest application , running in tomcat. use maven build process. build works without errors.
tomcat extract rest.war without raising error , try request http://hostname:8080/rest/categoryservice/category/01. leads 404 response. enclosed web.xml, beans.xml , snippet of service class. pom contains dependencies. hope have suggestions or hints find out mistake.
service class:
@path("/categoryservice") @produces({"application/json","application/xml"}) public class categoryservice { @get @path("/category/{id}") @produces({"application/json","application/xml"}) public category getcategory(@pathparam("id") string id) { ...
web.xml:
<?xml version="1.0" encoding="iso-8859-1"?> <!doctype web-app public "-//sun microsystems, inc.//dtd web application 2.3//en" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <context-param> <param-name>contextconfiglocation</param-name> <param-value>web-inf/beans.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.contextloaderlistener </listener-class> </listener> <servlet> <servlet-name>cxfservlet</servlet-name> <display-name>cxf servlet</display-name> <servlet-class> org.apache.cxf.transport.servlet.cxfservlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>cxfservlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
beans.xml:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> <import resource="classpath:meta-inf/cxf/cxf.xml" /> <import resource="classpath:meta-inf/cxf/cxf-servlet.xml" /> <jaxrs:server id="categoryrestservice" address="/"> <jaxrs:servicebeans> <ref bean="categoryservice" /> </jaxrs:servicebeans> </jaxrs:server> <bean id="categoryservice" class="demo.restful.categoryservice"> <property name="categorydao"> <ref bean="categorydao" /> </property> </bean>
this url should hit service: http://hostname:8080/rest/categoryservice/category/1
this url should return _wadl http://hostname:8080/rest/categoryservice?_wadl
this url should return list of available services http://hostname:8080/rest/categoryservice/
normally give more concrete url-pattern example:
<servlet-mapping> <servlet-name>cxfservlet</servlet-name> <url-pattern>/restapi/*</url-pattern> </servlet-mapping>
in case, url should return list of available services http://hostname:8080/rest/restapi/categoryservice/
Comments
Post a Comment