使用Spring和CXF servlet进行Tomcat部署失败

时间:2013-03-31 21:18:18

标签: spring tomcat cxf

我正在尝试运行包含Spring安全性的示例,但是我从web.xml中删除了该部分。现在它看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd“&GT;

 <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/cxf.xml</param-value>
    </context-param>


    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>


    <servlet>
        <display-name>CXF Servlet</display-name>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<!-- 
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                WEB-INF/cxf.xml
                WEB-INF/applicationContext-security.xml
            </param-value>
        </init-param>
-->
        <load-on-startup>1</load-on-startup>
    </servlet>


    <servlet>
        <servlet-name>fsmsc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>spring.profiles.active</param-name>
            <param-value>test-profile</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>

    </servlet>

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/static/*</url-pattern>
    </servlet-mapping>


    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/cxf/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>fsmsc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

...

部署时,我收到此错误:

  
    

SEVERE:将上下文初始化事件发送到类的侦听器实例的异常     org.springframework.web.context.ContextLoaderListener     java.lang.NoClassDefFoundError:     org / codehaus / jettison / mapped / TypeConverter at     java.lang.Class.getDeclaredConstructors0(Native Method)at     java.lang.Class.privateGetDeclaredConstructors(Class.java:2398)at at     java.lang.Class.getDeclaredConstructors(Class.java:1838)at     org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:229)       在     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:962)       在     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:935)       在     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)       在     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)       在     org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:294)       在     org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)       在     org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)       在     org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)       在     org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)       在     org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)       在     org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)       在     org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)       在     org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)       在     org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)       在     org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)       在     org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)       在     org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       在     org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)       在     org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)       在     org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)       在     org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)       在     org.apache.catalina.startup.HostConfig $ DeployWar.run(HostConfig.java:1655)       在     java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:439)       at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:303)       在java.util.concurrent.FutureTask.run(FutureTask.java:138)at     java.util.concurrent.ThreadPoolExecutor中的$ Worker.runTask(ThreadPoolExecutor.java:895)       在     java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:918)       在java.lang.Thread.run(Thread.java:662)引起:     抛出java.lang.ClassNotFoundException:     org.codehaus.jettison.mapped.TypeConverter at     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)       在     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)       ......还有32个

  

1 个答案:

答案 0 :(得分:3)

NoClassDefFoundError意味着您的类路径中没有该类(org / codehaus / jettison / mapped / TypeConverter)。该类包含在jettison jar中,这是CXF的依赖。

要解决您的问题,请检查war文件或项目依赖项是否已放弃。

更多:看起来像是在cxf-rt-rs-extension-providers pom.xml上使用提供的范围声明了jettison。这意味着您必须手动将jettison依赖项直接添加到您的pom.xml。我查看了最新版本的CXF:2.7.3。