spring+cxf No bean named 'cxf' available

最近項目中須要用到webservice,在spring中集成cxf時一直報錯:java

嚴重: StandardWrapper.Throwable org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' available at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1213) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1086) at org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:80)web

網上給出的最多的解決方案是:spring

<import resource="classpath:META-INF/cxf/cxf.xml"/> apache

<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>mvc

另外就是說spring版本和cxf版本不匹配等。app

試了不少種方案都不行,最後嘗試修改配置文件解決了;spa

修改前:xml

web.xmlblog

<servlet>
		<servlet-name>springmvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:springmvc-servlet.xml,classpath:springContext-cxf.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
</servlet>

修改方案:將springContext-cxf.xml配置文件導入到springmvc-servlet.xml文件中token

修改後代碼

web.xml

<servlet>
		<servlet-name>springmvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:springmvc-servlet.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
</servlet>

springmvc-servlet.xml

 <!-- 導入webservice接口配置文件 -->
    <import resource="classpath:applicationContext-cxf.xml" />
</beans> 

問題解決,我用的是spring5.0+cxf 3.1,親測這個不在版本不匹配問題。

相關文章
相關標籤/搜索