javax.management.InstanceAlreadyExistsException:spring.application:type = JobExecution,name = DATSFileFeeds

时间:2015-10-15 14:29:09

标签: spring-batch

我正在尝试在单个tomcat服务器实例中部署两个战争。但它正在抛出错误。有人可以帮忙吗? PFB错误日志。

  

19:39:28,294 ERROR pool-2-thread-1 context.ContextLoader:220 - 上下文初始化失败   org.springframework.context.ApplicationContextException:无法启动bean' batchMBeanExporter&#39 ;;嵌套异常是org.springframework.jmx.export.UnableToRegisterMBeanException:无法使用key' spring.application注册MBean [org.springframework.batch.admin.jmx.SimpleJobExecutionMetrics@1f069c]:type = JobExecution,name = DATSFileFeeds&# 39 ;;嵌套异常是javax.management.InstanceAlreadyExistsException:spring.application:type = JobExecution,name = DATSFileFeeds       在org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:169)       在org.springframework.context.support.DefaultLifecycleProcessor.access $ 1(DefaultLifecycleProcessor.java:154)       在org.springframework.context.support.DefaultLifecycleProcessor $ LifecycleGroup.start(DefaultLifecycleProcessor.java:335)       在org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:143)       在org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:108)       在org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:908)       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:428)       在org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)       在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)       在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)       在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)       at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       在org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:897)       在org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:873)       在org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)       在org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)       在org.apache.catalina.startup.HostConfig $ DeployWar.run(HostConfig.java:1599)       at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)       在java.util.concurrent.FutureTask.run(FutureTask.java:262)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:744)   引起:org.springframework.jmx.export.UnableToRegisterMBeanException:无法使用key' spring.application注册MBean [org.springframework.batch.admin.jmx.SimpleJobExecutionMetrics@1f069c]:type = JobExecution,name = DATSFileFeeds&# 39 ;;嵌套异常是javax.management.InstanceAlreadyExistsException:spring.application:type = JobExecution,name = DATSFileFeeds       在org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:602)       在org.springframework.batch.admin.jmx.BatchMBeanExporter.registerJobs(BatchMBeanExporter.java:190)       在org.springframework.batch.admin.jmx.BatchMBeanExporter.doStart(BatchMBeanExporter.java:353)       在org.springframework.batch.admin.jmx.BatchMBeanExporter.start(BatchMBeanExporter.java:307)       在org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:166)       ......还有22个   引起:javax.management.InstanceAlreadyExistsException:spring.application:type = JobExecution,name = DATSFileFeeds       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)       在org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:169)       在org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:655)       在org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:598)       ......还有26个

2 个答案:

答案 0 :(得分:3)

您可以使用MBeanRegistrationSupport#setRegistrationPolicy方法配置MBean注册的行为。

目前有三项政策:

  1. FAIL_ON_EXISTING - 尝试时注册失败 以已存在的名称注册MBean。
  2. IGNORE_EXISTING - 在尝试以已经使用的名称注册MBean时,注册应该忽略受影响的MBean 存在。
  3. REPLACE_EXISTING - 在尝试以已经使用的名称注册MBean时,注册应该替换受影响的MBean 存在。

答案 1 :(得分:0)

您可以有条件地注册MBean:

//Get the MBean server
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
//register the MBean
number = new NumberOfSomething();
ObjectName name = new ObjectName("ru.pochta.abon.mbean:type=NumberOfSomething");
if (!mbs.isRegistered(name)) {
    mbs.registerMBean(number, name);
}