繁体   English   中英

如何从测试App上下文中排除Spring Boot应用程序bean?

[英]How to exclude spring boot application beans from the test App context?

我目前正在定义我的基本规范,如下所示:

@Configuration
@ActiveProfiles(profiles = "test")
@ContextConfiguration(locations = "classpath:test-config-context.xml" )
class SpringSharedSpecification extends Specification 

这也最终导致处理我的父application-context.xml

我正在使用活动配置文件选项来不加载主bean并使用下面用于跳过应用程序上下文bean的test-config执行,但并不认为这是最好的方法。 任何人都可以提出跳过application-context.xml的更好方法吗?

<beans profile="!test"> 

预先感谢您的回答。

您可以在bean类上使用注释:

@Component
@Profile("!test")
class MyProductionBean {
}

暂无
暂无

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

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