Spring Integration CXF to develop RESTful style webservice error Servlet with a name javax.ws.rs.core.Application is not available

Spring Integration with Apache CXF to develop RESTful style webservice service, and reported the following error

javax.servlet.ServletException: Servlet with a name javax.ws.rs.core.Application is not available
	at org.apache.cxf.jaxrs.servlet.sci.JaxrsServletContainerInitializer.getServletMapping(JaxrsServletContainerInitializer.java:147)
	at org.apache.cxf.jaxrs.servlet.sci.JaxrsServletContainerInitializer.onStartup(JaxrsServletContainerInitializer.java:104)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1125)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1859)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Engineering structures:
Here Insert Picture Description

Spring configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:soap="http://cxf.apache.org/bindings/soap"
       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-4.3.xsd  
       http://www.springframework.org/schema/tx  
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/context  
       http://www.springframework.org/schema/context/spring-context.xsd  
       http://www.springframework.org/schema/aop  
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://cxf.apache.org/bindings/soap 
       http://cxf.apache.org/schemas/configuration/soap.xsd 
       http://cxf.apache.org/jaxws 
       http://cxf.apache.org/schemas/jaxws.xsd
       http://cxf.apache.org/jaxrs
       http://cxf.apache.org/schemas/jaxrs.xsd
       http://cxf.apache.org/jaxrs
       http://cxf.apache.org/schemas/jaxrs.xsd">

	<!-- 配置spring创建容器是要扫描的包 -->
	<context:component-scan base-package="cn.itcast" />
	
	<jaxrs:server address="/service">
		<jaxrs:serviceBeans>
			<ref bean="userService"></ref>
		</jaxrs:serviceBeans>
	</jaxrs:server>
	
	<bean id="userService" class="cn.itcast.service.impl.UserServiceImpl"></bean>

</beans>

web.xml configuration:

	<?xml version="1.0" encoding="UTF-8"?>
	<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">

  	<!-- 配置spring监听器 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- 指定spring配置文件位置 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/applicationContext.xml</param-value>
	</context-param>
	
	<!-- CXFServlet配置 -->
	<servlet>
		<servlet-name>CXFServlet</servlet-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>/webservice/*</url-pattern>
	</servlet-mapping>

</web-app>

Find a day, did not find a solution, it seems never even met people like me this question. . .
At present only a preliminary study webservice, not use maven! !
So I put all the jar package lib directory cxf are copied directly to the project inside, to prevent the problem dependent error.
But still reported the Servlet with a name javax.ws.rs.core.Application is not available
I really headache

Big brother can hope pointing or two! ! !

Published 23 original articles · won praise 1 · views 1646

Guess you like

Origin blog.csdn.net/weixin_43978412/article/details/99722115