CXF资源访问不到~

发布于 2021-11-29 11:55:49 字数 7992 浏览 911 评论 1

测试环境Java1.8 tomcat8 Sping4 CXF3

@Path(value="Service")
public interface MyService {
      
    @GET
    @Path("/echo/{input}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public String ping(@PathParam("input") String input);
}

@Service("Service")
public class MyServiceImpl implements MyService {

	@Override
	public String ping(String input) {
		return input; 
	}
}



cxf配置
<?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"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.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" />
	<context:annotation-config />
	<context:component-scan base-package="cn.z201.service.api" /> 
	<bean id="inMessageInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" />
	<bean id="outMessageInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
	<bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor" />
	<bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
	<!-- 亦可在 jaxrs:server 内配置jaxrs:inInterceptors 拦截器,如下边注释掉的 -->
	<bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus">
		<property name="inInterceptors">
			<list>
				<ref bean="logInbound" />
			</list>
		</property>
		<property name="outInterceptors">
			<list>
				<ref bean="logOutbound" />
			</list>
		</property>
		<property name="outFaultInterceptors">
			<list>
				<ref bean="logOutbound" />
			</list>
		</property>
		<property name="inFaultInterceptors">
			<list>
				<ref bean="logInbound" />
			</list>
		</property>
	</bean>
	
	<jaxrs:server id="Services" address="/"> 
		<jaxrs:serviceBeans>
			<ref bean="Service" />
		</jaxrs:serviceBeans>
		<!-- 支持的协议 -->
	</jaxrs:server>
</beans>



2015-10-17 20:05:34 ZengDemo INFO  [org.apache.cxf.interceptor.LoggingInInterceptor:253] | Inbound Message
----------------------------
ID: 1
Address: http://127.0.0.1:8080/Zeng/cxf
Encoding: UTF-8
Http-Method: GET
Content-Type: 
Headers: {Accept=[image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, */*], accept-encoding=[gzip, deflate], accept-language=[zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3], connection=[Keep-Alive], Content-Type=[null], cookie=[JSESSIONID=FD15C5C613B14B1FAF6DEAEDF8C5C3DE], dnt=[1], host=[127.0.0.1:8080], user-agent=[Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/8.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)]}
--------------------------------------
2015-10-17 20:05:34 ZengDemo WARN  [org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor:166] | No root resource matching request path /Zeng/cxf has been found, Relative Path: /. Please enable FINE/TRACE log level for more details.
2015-10-17 20:05:34 ZengDemo WARN  [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper:72] | javax.ws.rs.NotFoundException: HTTP 404 Not Found
	at org.apache.cxf.jaxrs.utils.SpecExceptions.toNotFoundException(SpecExceptions.java:89)
	at org.apache.cxf.jaxrs.utils.ExceptionUtils.toNotFoundException(ExceptionUtils.java:122)
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:169)
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:77)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
	at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)
	at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
	at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:217)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

2015-10-17 20:05:35 ZengDemo INFO  [org.apache.cxf.interceptor.LoggingOutInterceptor:253] | Outbound Message
---------------------------
ID: 1
Response-Code: 404
Content-Type: 
Headers: {Date=[Sat, 17 Oct 2015 12:05:34 GMT], Content-Length=[0]}
--------------------------------------






如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不乱于心 2021-11-30 04:35:49

解决了Path写太多了。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文