简体   繁体   English

BeanCreationException:创建名为“springApplicationAdminRegistrar”的 bean 时出错。 InstanceAlreadyExistsException

[英]BeanCreationException: Error creating bean with name 'springApplicationAdminRegistrar'. InstanceAlreadyExistsException

I have 2 spring boot applications.我有 2 个弹簧启动应用程序。

application_A dependsn_on application_B application_A 依赖于 application_B

Actually each of applications has main class marked as @SpringBootApplication实际上每个应用程序都有标记为@SpringBootApplication的主类

application_B starts successfully but application_A doesn't start: application_B成功启动,但application_A未启动:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springApplicationAdminRegistrar' defined in class path resource [org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Admin,name=SpringApplication # JMX name of the application admin MBean.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    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:761)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at pack.Application.main(Application.java:36)
Caused by: javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Admin,name=SpringApplication # JMX name of the application admin MBean.
    at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
    at org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar.afterPropertiesSet(SpringApplicationAdminMXBeanRegistrar.java:92)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 15 common frames omitted

In debug I see that spring executes org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration#springApplicationAdminRegistrar twice during startup and fails.在调试中,我看到 spring 在启动期间执行org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration#springApplicationAdminRegistrar两次并失败。

I tried to set property:我试图设置属性:

 spring.application.admin.enabled=false

But it doesn't help me.但这对我没有帮助。

How can I avoid this exception?我怎样才能避免这个异常?

PS附言

I've found this one https://github.com/spring-projects/spring-boot/issues/6378 but there is no solution我找到了这个https://github.com/spring-projects/spring-boot/issues/6378但没有解决方案

The SpringApplicationAdminJmxAutoConfiguration has the code like: SpringApplicationAdminJmxAutoConfiguration的代码如下:

String jmxName = this.environment.getProperty(JMX_NAME_PROPERTY,
            DEFAULT_JMX_NAME);
    if (this.mbeanExporters != null) { // Make sure to not register that MBean twice
        for (MBeanExporter mbeanExporter : this.mbeanExporters) {
            mbeanExporter.addExcludedBean(jmxName);
        }
    }
    return new SpringApplicationAdminMXBeanRegistrar(jmxName);

Where we have those constants:我们有这些常量的地方:

/**
 * The property to use to customize the {@code ObjectName} of the application admin
 * mbean.
 */
private static final String JMX_NAME_PROPERTY = "spring.application.admin.jmx-name";

/**
 * The default {@code ObjectName} of the application admin mbean.
 */
private static final String DEFAULT_JMX_NAME = "org.springframework.boot:type=Admin,name=SpringApplication";

So, you should consider to make that jmx-name as unique for each application.因此,您应该考虑使jmx-name对于每个应用程序都是唯一的。 I mean you need specify spring.application.admin.jmx-name configuration property.我的意思是你需要指定spring.application.admin.jmx-name配置属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建名称为springApplicationAdminRegistrar的bean时出错 - Error creating bean with name springApplicationAdminRegistrar 创建名为“springApplicationAdminRegistrar”的 bean 时出错: - Error creating bean with name 'springApplicationAdminRegistrar': BeanCreationException:创建在ServletContext中定义的名称为“ /”的bean时出错 - BeanCreationException: Error creating bean with name '/' defined in ServletContext Spring BeanCreationException:创建名称为bean的错误 - Spring BeanCreationException: Error creating bean with name BeanCreationException:创建名称为servletContainer的bean时出错 - BeanCreationException: Error creating bean with name servletContainer BeanCreationException:创建名称为“flywayInitializer”的 bean 时出错 - BeanCreationException: Error creating bean with name 'flywayInitializer' 创建名称为'transactionManager的bean时出错:BeanCreationException - Error creating bean with name 'transactionManager : BeanCreationException BeanCreationException:创建名称为'entityManagerFactory'的bean时出错 - BeanCreationException: Error creating bean with name 'entityManagerFactory' BeanCreationException:创建名称为“ initDbService”的bean时出错 - BeanCreationException: Error creating bean with name 'initDbService' Spring Boot-多个上下文“在类路径资源中创建名称为'springApplicationAdminRegistrar'的bean时出错” - Spring Boot - Multiple Contexts “Error creating bean with name 'springApplicationAdminRegistrar' defined in class path resource”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM