springspring-bootjmxnosuchmethoderrormbeans

java.lang.NoSuchMethodError: org.springframework.jmx.support.MBeanServerFactoryBean.getObject()Ljavax/management/MBeanServer;


I am trying to use MbeanServer jmx support and getting below exception for MbeanServer :

Caused by: java.lang.NoSuchMethodError: org.springframework.jmx.support.MBeanServerFactoryBean.getObject()Ljavax/management/MBeanServer;
    at com.ctil.PaymentsApplication.mbeanServer(PaymentsApplication.java:239)
    at com.ctil.PaymentsApplication$$EnhancerBySpringCGLIB$$411b63e3.CGLIB$mbeanServer$3(<generated>)
    at com.ctil.PaymentsApplication$$EnhancerBySpringCGLIB$$411b63e3$$FastClassBySpringCGLIB$$c3de57c.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
    at com.ctil.PaymentsApplication$$EnhancerBySpringCGLIB$$411b63e3.mbeanServer(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    ... 28 more

I am using openjdk-8 and wildfly jboss server, no compile time errors.

Class configurations anotations:

@Configuration
@EnableJpaRepositories
@EnableJpaAuditing
@Import({ RepositoryRestMvcConfiguration.class,JMSSQSConfig.class})
@ComponentScan
@EnableAutoConfiguration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableTransactionManagement(proxyTargetClass = true)
@EnableScheduling

Methods which are throwing errors :

@Bean
    public MBeanServer mbeanServer()  {
        System.out.println("INSIDE FACTORY CREATE******");
        SpecificPlatform platform = SpecificPlatform.get();
        if (platform != null) {
            return platform.getMBeanServer();
        }
        MBeanServerFactoryBean factory = new MBeanServerFactoryBean();
        factory.setLocateExistingServerIfPossible(true);
        factory.afterPropertiesSet();
        return factory.getObject();
    }


@Bean
public AnnotationMBeanExporter annotationMBeanExporter() throws MalformedObjectNameException {
    AnnotationMBeanExporter exporter = new AnnotationMBeanExporter();
    ObjectName name = new ObjectName("com.ctil.payments.transactionProcessor","transacionProcessorConfiguration","TransactionProcessorConfiguration");
    exporter.setServer(mbeanServer());
    exporter.setDefaultDomain("com.ctil.payments.transactionProcessor");

    if (!exporter.getServer().isRegistered(name)) {

        TransactionProcessorConfiguration config = new TransactionProcessorConfiguration();
        exporter.registerManagedResource(config, name);

    }
    return exporter;

}

Pom.xml :

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat-jdbc</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>javax.xml.soap</groupId>
            <artifactId>saaj-api</artifactId>
            <version>1.3.5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-ws</artifactId>
        </dependency>

        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
        </dependency>

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jmx</artifactId>
             <version>2.0.8</version>
        </dependency> 

I am using ubuntu 16.04, 64 bit machine. Please note that all this configuration are working in windows system. I have also tried using oracle-8 jdk but getting same error. Looks like versioning issue but not able to resolve it.


Solution

  • Remove following from your pom.xml:

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jmx</artifactId>
            <version>2.0.8</version>
        </dependency>