MAVEN搭建WEB环境问题

来源:互联网 发布:算法导论书在线观看 编辑:程序博客网 时间:2024/06/05 08:45
问题一:搭建完成后启动tomcat总是 No bean named 'cxf' is defined错误,在网上找了好多资料,终于搞定了该问题。下面是具体需要检查的内容:
解决方案:
1、需要将工程的Spring配置文件放到 src/main/resources下(千万不能和web.xml文件一起放到WEB-INF下面,之前就是因为放到这个下面了,配置文件一直没有加载上,导致一直报错,太蛋疼了);
2、web.xml配置文件(注意加粗的地方)
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="web" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <display-name>Archetype Created Web Application</display-name>
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext-*.xml</param-value>
 </context-param>
 <!-- Spring配置 -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 
 <!-- Spring的log4j监听器 -->
 <listener>
  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener>
 <!-- CXF配置 -->
 <servlet>
  <servlet-name>CXFService</servlet-name>
  <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>CXFService</servlet-name>
  <url-pattern>/webservice/*</url-pattern>
 </servlet-mapping>
</web-app>
3、spring配置文件applicationContext-base.xml(注意加粗的地方)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
 xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:jaxws="http://cxf.apache.org/jaxws"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-2.5.xsd
 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.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-xml.xml" />
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

        <bean id="CXFDemoImpl" class="com.deppon.fims.inter.uums.CXFDemoImpl" />
        <jaxws:endpoint id="cxfDemo" implementor="#CXFDemoImpl" address="/cxfdemo" />
 
 <context:annotation-config />
 <context:component-scan base-package="com.deppon" />
</beans>
以上三步可搞定这个问题,如果还搞不定就只能找度娘了


0 0