@Configuration

@Configuration注解的类里面都是含有带有@Bean注解的方法,这些配置类相当于声明了bean的xml,添加@Configuration的目的有一方面是为了能被@ComponentScan自动扫描到.换句话说,在没有手动地明确地将配置类加入到SpringApplication.run()sources参数时,给配置类加上@Configuration就必须有一个类加了@ComponentScan,使@Configuration注解的配置类可以被扫描到(被添加到spring应用上下中)

可以把@Configuration当成是和@Service等一样的注解

更详细见15.1 Importing additional configuration classes

results matching ""

    No results matching ""