在春季,如果不像下面的示例那样仅将@EnableWebMvc
与@Configuration
一起使用,而会与@EnableWebMvc
一起使用怎么办?
使用@Configuration
@Configuration
@EnableWebMvc
public class Clazz {
// ..
}
没有@Configuration
@EnableWebMvc
public class Clazz {
// ..
}
答案 0 :(得分:1)
@EnableWebMvc
本身不能做很多事情,除非它被Spring发现。 Spring搜索标记为@Component
的类。 @Configuration
被标记为@Component
,因此所有被标记为@Configuration
的类被Spring组件扫描发现的方式与被标记为@Component
的类相同。只有标记了@EnableWebMvc
或标记为@Component
的任何注释时,才会发现标记为@Component
的类