标签:需要 code .class 写法 测试 加载 命名 layer scan
@ContextConfiguration(class=CDPlayerConfig.class)
注解@ContextConfiguration 会告诉它需要在 CDPlayerConfig 中加载配置。
CDPlayConfig.class的写法
@Configuration
@ComponentScan
public class CDPlayConfig {
}
@Configuration表示这是一个配置类,@ComponentScan这个注解能够在 Spring 中启用组件扫描,如果没有其他配置的话,@ComponentScan 默认会扫描与配置类相同的包。
如果使用 XML 来启用组件扫描的话,那么可以使用 Spring context 命名空间的 <context:component-scan> 元素。
换句话说@ContextConfiguration(class=CDPlayerConfig.class)就表示测试单元可以使用CDPlayerConfig扫描到到所有bean。
标签:需要 code .class 写法 测试 加载 命名 layer scan
原文地址:https://www.cnblogs.com/bihanghang/p/10023759.html