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

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

我正在尝试使用 MbeanServer jmx 支持和 低于 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$1b63e3.CGLIB$mbeanServer(<generated>)
    at com.ctil.PaymentsApplication$$EnhancerBySpringCGLIB$1b63e3$$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$1b63e3.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

我正在使用 openjdk-8 和 wildfly jboss 服务器,没有编译时错误。

Class 配置注释:

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

抛出错误的方法:

@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> 

我正在使用 ubuntu 16.04,64 位机器。 请注意,所有这些配置都适用于 windows 系统。 我也尝试过使用 oracle-8 jdk 但得到同样的错误。 看起来像是版本控制问题,但无法解决。

从您的 pom.xml 中删除以下内容:

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