简体   繁体   中英

How to perform integration testing in Spring Boot with Gemfire and multiple Spring Application Configurations?

I'm trying to run an integration test that has a different SpringApplicationConfiguration from the other integration tests. The issue only manifests when Gemfire is configured.

A demonstration of the error in available here: https://github.com/kemitix/test-spring-boot-gemfire-testing

There are two test classes ContextsApplicationTests and ContextsApplicationWithCustomTests .

The first uses a standard SpringApplicationConfiguration based on the ContextsApplication class. The other attempts to also include the CustomConfiguration class to override a Bean.

Test one:

@IntegrationTest
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ContextsApplication.class)
public class ContextsApplicationTests {
...

Test two:

@IntegrationTest
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {
    ContextsApplication.class,
    CustomConfiguration.class
})
public class ContextsApplicationWithCustomTests {

Without having Gemfire enabled the tests run happily.

However, having Gemfire configured causes an issue with the context loader throwing an IllegalArgumentException :

Caused by: java.lang.IllegalArgumentException: 
    a beanFactoryReference already exists for key cacheFactoryBean

The full output is included in the file mvn-clean-install.txt in the repo.

When the two tests are run in isolation they work. It is only when they are run together that the issue appears. I suspect the Gemfire instance that Spring Boot is running is causing some sort of bleed-over between the two tests that is causing the Contexts not to be properly segregated. Unfortunately, I've no idea how to influence this.

您也可以尝试CacheFactoryBean.setUseBeanFactoryLocator(false)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM