当前位置:  开发笔记 > 后端 > 正文

无法使用apache cxf在Apache tomcat中部署项目

如何解决《无法使用apachecxf在Apachetomcat中部署项目》经验,为你挑选了2个好方法。

我使用spring 4.2.4,apache cxf 3.1.4和maven 3.0创建了一个soap web服务.当我尝试部署应用程序时,我收到如下错误:

WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pdpservice': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.isCglibProxyClass(Ljava/lang/Class;)Z
Dec 21, 2015 3:12:34 PM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pdpservice': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.isCglibProxyClass(Ljava/lang/Class;)Z
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5077)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5591)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.isCglibProxyClass(Ljava/lang/Class;)Z
    at org.apache.cxf.common.util.SpringAopClassHelper.getRealClassInternal(SpringAopClassHelper.java:85)
    at org.apache.cxf.common.util.ClassHelper.getRealClass(ClassHelper.java:65)
    at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:150)
    at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
    at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:251)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:539)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1706)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1645)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 21 more

当我尝试调试这个我开始知道,我的代码引用了下面的类org.springframework.aop.support.AopUtils.isCglibProxyClass而不是org.springframework.util.ClassUtils.isCglibProxyClass.

参考: Bean创建在构建时抛出异常

我不知道我做错了什么.下面给出了POM.xml


    ...
    
        4.2.4.RELEASE
        3.1.4
    
    
    
    
        org.springframework
        spring-core
        ${spring.version}
    
    
        org.springframework
        spring-beans
        ${spring.version}
    
    
        org.springframework
        spring-webmvc
        ${spring.version}
    
    
        org.springframework
        spring-aop
        ${spring.version}
    
    
    
        org.apache.cxf
        cxf-core
        ${cxf.version}
        compile
    
    
        org.apache.cxf
        cxf-rt-bindings-soap
        ${cxf.version}
        compile
    
    
        org.apache.cxf
        cxf-rt-frontend-jaxws
        ${cxf.version}
        compile
    
    
        org.apache.cxf
        cxf-rt-transports-http
        ${cxf.version}
        compile
    
    
        org.apache.cxf
        cxf-rt-rs-extension-providers
        ${cxf.version}
        compile
    
    
        org.apache.cxf
        cxf-bundle
        2.7.18
        compile
        
            
                org.springframework
                *
            
            
                org.eclipse.jetty
                *
            
            
                org.apache.geronimo.specs
                *
            
        
    
    
        org.apache.cxf
        cxf-tools-java2ws
        ${cxf.version}
    
    
    
    ....
    

我的服务类:

package com.pd.service;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import com.pd.service.bean.Product;

@WebService(targetNamespace="http://service.pd.com/")
public interface PDService {

    @WebMethod
     public Product getProduct(@WebParam(name = "arg0") int id);
    @WebMethod
     public List getAllProducts();

}

我的服务类实现:

package com.pd.service.impl;

import java.util.List;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;

import com.pd.service.PDService;
import com.pd.service.bean.Product;
import com.pd.service.dao.PDServiceDAO;

@WebService(targetNamespace="http://impl.service.pd.com/", endpointInterface="com.pd.service.PDService")
public class PDServiceImpl implements PDService {

    @Autowired
    PDServiceDAO pdServiceDAO;

    @Override
    public Product getProduct(int id) {
        return pdServiceDAO.getProduct(id);
    }

    @Override
    public List getAllProducts() {
        return pdServiceDAO.getAllProducts();
    }
}

你能帮帮我吗?提前致谢.



1> Gary Russell..:

CXF的那个版本与春4.2.x版兼容 - 这些方法在Spring 3.1中不建议使用在Spring 4.2中删除.

请参阅此处的提交.CXF需要更改要使用的方法调用ClassUtils#isCglibProxyClass(Class).

您必须与CXF人员核实,看看他们是否有适用于Spring 4.2的版本.


我在Apache CXF网站上进行了检查:http://cxf.apache.org/docs/30-migration-guide.html这样我得到了“需要Spring 3.2或更高版本。对Spring 3中弃用的API的调用.x已删除。这使CXF 3.0可以在Spring 4中使用,但是意味着它不再可以在Spring 2.5中使用。”
请参阅https://issues.apache.org/jira/browse/CXF-6511,看起来它就是你在垃圾邮件中的2.7.18版本,这就是问题所在.

2> Brumlebarten..:

将CXF从2.7.18提升到3.2.0为我解决了这个问题.

CXF需要被碰着主要版本3,支持春4.2.x版.

请注意,OP使用CXF 2.7.18作为工件cxf-bundle.这就是造成麻烦的原因.

推荐阅读
重庆制造漫画社
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有