【问题标题】:How to exclude spring boot application beans from the test App context?如何从测试 App 上下文中排除 Spring Boot 应用程序 bean?
【发布时间】:2018-08-24 14:32:46
【问题描述】:

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

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

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

我正在使用活动配置文件选项来不加载主 bean 并使用 test-config 执行 我在下面使用跳过应用程序上下文 bean,但不认为这是最好的方法。谁能建议跳过 application-context.xml 的更好方法?

<beans profile="!test"> 

提前感谢您的回答。

【问题讨论】:

    标签: spring unit-testing spring-boot javabeans spock


    【解决方案1】:

    你可以在你的 bean 类上使用注解:

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

    【讨论】:

    • 很高兴你。您能否将此答案标记为“已接受”(按绿色标记)
    猜你喜欢
    • 2017-02-05
    • 2018-01-20
    • 2022-01-13
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 1970-01-01
    相关资源
    最近更新 更多