Reputation: 13406
I'm new to Maven, Spring and CXF and am currently trying to get a small 'Hello World' thing going where I have a REST Service available for use. I've spent a day on this and still I'm getting the dreaded "No services have been found." error when I run my project on Tomcat inside Eclipse. Below I've posted the important code from a few files. I'm hoping someone can tell me what I'm doing wrong:
web.xml:
<web-app>
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/beans.xml</param-value>
</context-param>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</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:jaxws="http://cxf.apache.org/jaxws"
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 http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="bookserviceclass" class="org.ahmad.restTest1.restServices.BookService" />
<jaxrs:server id="bookservice" address="/">
<jaxrs:serviceBeans>
<ref bean="bookserviceclass" />
</jaxrs:serviceBeans>
</jaxrs:server>
</beans>
BookService.java:
package org.ahmad.restTest1.restServices;
import org.ahmad.restTest1.vo.BookVO;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
@Path("/")
public class BookService {
private static HashMap < BookVO, BookVO > hashMap;
@GET
@Path("/randomMsg/{name}")
@Produces({
MediaType.APPLICATION_JSON
})
public Response getSomeMessage(@PathParam("name") String name) {
return Response.ok(name + "123").build();
}
}
Upvotes: 2
Views: 6664
Reputation: 39261
You have some configuration errors.
Include spring listener in web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Remove this lines in beans.xml
. They are not needed in latest versions of CXF
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
After this, the server will be available executing
http://localhost:8080/yourdeploydir/randomMsg/hello
Upvotes: 4