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

时间:2017-11-09 09:49:11

标签: spring spring-boot jmx nosuchmethoderror mbeans

我正在尝试使用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$$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

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

类配置anotations:

@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但得到同样的错误。 看起来像版本问题,但无法解决它。

1 个答案:

答案 0 :(得分:0)

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

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