收到 "No services have been found." 错误
Getting "No services have been found." error
我是 Maven、Spring 和 CXF 的新手,目前正在尝试在我有可用的 REST 服务的地方做一个小的 'Hello World' 事情。我在这上面花了一天时间,当我在 Eclipse 中 运行 我的 Tomcat 项目时,我仍然遇到可怕的 "No services have been found." 错误。下面我发布了一些文件中的重要代码。我希望有人能告诉我我做错了什么:
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();
}
}
您有一些配置错误。
在 web.xml
中包含 spring 侦听器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
删除 beans.xml
中的这一行。最新版本的 CXF 不需要它们
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
在此之后,服务器将可以执行
http://localhost:8080/yourdeploydir/randomMsg/hello
我是 Maven、Spring 和 CXF 的新手,目前正在尝试在我有可用的 REST 服务的地方做一个小的 'Hello World' 事情。我在这上面花了一天时间,当我在 Eclipse 中 运行 我的 Tomcat 项目时,我仍然遇到可怕的 "No services have been found." 错误。下面我发布了一些文件中的重要代码。我希望有人能告诉我我做错了什么:
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();
}
}
您有一些配置错误。
在 web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
删除 beans.xml
中的这一行。最新版本的 CXF 不需要它们
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
在此之后,服务器将可以执行
http://localhost:8080/yourdeploydir/randomMsg/hello