English 中文(简体)
测试:目前尚无法登记甲基溴
原标题:Testing: Unable to register MBean instance already exists

我们进行了几次融合测试,但最近在@ManagedResource正在遇到一个问题:

Unable to register MBean [com.api.configuration.ApiConfiguration@63fde7ca] with key  apiConfiguration ; nested exception is javax.management.InstanceAlreadyExistsException: api:name=ApiConfiguration

犯罪主人也喜欢:

@Component
@ManagedResource(objectName = "api:name=ApiConfiguration")
public class ApiConfiguration {

    @ManagedOperation   
    public void reloadConfiguration() {
        // do something
    }

}

We have tried adding a @DirtiesContext on every integration test without success. The error only appears when running all tests from Maven or IntelliJ. If we run only one of the failing tests it works.

最佳回答

如果你使用java基配置,你只需要增加这一配置。

@EnableMBeanExport(registration=RegistrationPolicy.REPLACE_EXISTING)

页: 1

@EnableMBeanExport(registration=RegistrationPolicy.IGN页: 1E_EXISTING)

因此,它将取代或使用现有的信标(根据您的配置),不会造成任何错误。

问题回答

错误非常明显,已经存在,有人试图制造另一个错误。 它失败了。

当问题仅显示测试时,解决这一问题的一个办法是忽视重复生育者的登记:

<context:mbean-export registration="ignoreExisting"/>

或者如果你倾向于通知方式:

@Autowired
MBeanExporter mBeanExporter;

之后,又制定了<>光线<>的政策:

mBeanExporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);

该政策被设定为FAIL_ON_EXISTING。 您也可将其安排在REPLACE_EXISTING

如果在你的测试之上有“可变的阿托图”,则认为可以删除。 这有助于我。

在我的案件中,在测试期间发生了这种情况,第二个配置使得无法进行融合测试的jmx(和我的时间安排)得以解决问题。

@Configuration
@EnableScheduling
@EnableMBeanExport
@Profile("!integrationtest") // Do not run for the integrationtest profile 
public class SchedulingConfiguration {

}

你们还需要注意到你的测试,以便他们利用融合测试特征:

@SpringBootTest
@ActiveProfiles("integrationtest")
class XServiceTest {




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签