11

I have created a soap web service using spring 4.2.4, apache cxf 3.1.4 and maven 3.0. When I try to deploy the application, I am getting an error like below:

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

when i try to debug this i come to know, my code referring the below class org.springframework.aop.support.AopUtils.isCglibProxyClass Instead of org.springframework.util.ClassUtils.isCglibProxyClass.

Reference: Bean creation throws exception at the build time

I dont know what i did wrong. Below given the POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ...
    <properties>
        <spring.version>4.2.4.RELEASE</spring.version>
        <cxf.version>3.1.4</cxf.version>
    </properties>
    <dependencies>
    <!-- Spring framework -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <!-- Web Service runtime -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-core</artifactId>
        <version>${cxf.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-bindings-soap</artifactId>
        <version>${cxf.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-extension-providers</artifactId>
        <version>${cxf.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-bundle</artifactId>
        <version>2.7.18</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.geronimo.specs</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-tools-java2ws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    </dependencies>
    <build>
    ....
    </build>
</Project>

My Service class:

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<Product> getAllProducts();

}

My service class Implementation:

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<Product> getAllProducts() {
        return pdServiceDAO.getAllProducts();
    }
}

Could you please help me with this. Thanks in advance.

Community
  • 1
  • 1
Praveen Dhasarathan
  • 648
  • 2
  • 11
  • 24

4 Answers4

15

That version of cxf is not compatible with Spring 4.2.x - those methods were deprecated in Spring 3.1 and were removed in Spring 4.2.

See the commit here. CXF needs to change the method call to use ClassUtils#isCglibProxyClass(Class).

You'll have to check with the CXF folks to see if they have a version that works with Spring 4.2.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • 2
    I checked with Apache CXF site: http://cxf.apache.org/docs/30-migration-guide.html In that i got this "Spring 3.2 or newer is required.The calls to the API's that were deprecated in Spring 3.x have been removed.This allows CXF 3.0 to work with Spring 4, but means it can no longer work with Spring 2.5." – Praveen Dhasarathan Dec 22 '15 at 04:39
  • Could you please suggest me, why my code still using deprecated class. Is their any problem with my POM.xml – Praveen Dhasarathan Dec 22 '15 at 04:42
  • I don't know. All I can say is that method no longer exists. I don't know if a version of CXF exists that works with Spring 4.2. You'll have to check with them. – Gary Russell Dec 22 '15 at 05:12
  • Or, drop back to Spring 4.1.9 until they support 4.2. Since it's been deprecated since Spring 3.1 they should have fixed it by now. – Gary Russell Dec 22 '15 at 05:24
  • 2
    See https://issues.apache.org/jira/browse/CXF-6511 looks like it's your 2.7.18 version in the pom that's the problem. – Gary Russell Dec 22 '15 at 05:38
  • cxf bundle latest version is 2.7.18 only. cxf other jar having 3.1.4. I added cxf bundle because i got some other error. if i removed it, i am getting error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pdpservice': Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service {http://service.pdp.com/}PDPServiceImplService. – Praveen Dhasarathan Dec 22 '15 at 08:30
  • Sorry - you need help from the CXF people - I have told you what the problem is, you are using some CXF classes that are incompatible with Spring Framework 4.2. I can't help any more. Perhaps you should ask a new question about the error you got before adding in that old bundle. – Gary Russell Dec 22 '15 at 13:50
9

Bumping CXF from 2.7.18 to 3.2.0 fixed this issue for me.

CXF needs to be bumped to major version 3, which supports Spring 4.2.x.

Note that OP used CXF 2.7.18 for artifact cxf-bundle. This is what was causing the trouble.

Brumlebarten
  • 686
  • 6
  • 6
1

Upgrading to apache cxf to 3.2.0 fixed the issue for Spring Framework 5.0.1

kanaparthikiran
  • 523
  • 12
  • 15
0

Another way to avoid this problem while still using CXF 2.7.18 is to add the following system property: -Dorg.apache.cxf.useSpringClassHelpers=false. This makes CXF avoid Spring helpers usage, so the problem goes away.

Please note that CXF 2.7.18 is an ancient version, it has unfixed vulnerabilities and the best way to go is to upgrade it to the recent version as another answer suggests.

Roman Puchkovskiy
  • 11,415
  • 5
  • 36
  • 72