博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot之@SpringBootApplication注解
阅读量:4166 次
发布时间:2019-05-26

本文共 806 字,大约阅读时间需要 2 分钟。

@SpringBootApplication

由于大量项目都会在主要的配置类上添加 @Configuration  @EnableAutoConfiguration  @ComponentScan三个注解

因此Spring Boot提供了@SpringBootApplication注解,该注解可以替代上面三个注解(使用Spring注解继承实现)。

@Configuration

标注在类上,相当于把该类作为spring的xml配置文件中的<beans>

作用为:配置spring容器(应用上下文)

@Configurationpublic class TestConfiguration {    public TestConfiguration() {        System.out.println("TestConfiguration容器启动初始化。。。");    }}public class TestMain {    public static void main(String[] args) {        // 如果加载spring-context.xml文件:        // ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");        // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext        ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);    }}

 

转载地址:http://ukgxi.baihongyu.com/

你可能感兴趣的文章
socket 科普文章
查看>>
Mutex, semaphore, spinlock的深度解析
查看>>
pthread线程使用小结
查看>>
A Game of Thrones(59)
查看>>
2018.3.19
查看>>
A Game of Thrones(97)
查看>>
A Game of Thrones(98)
查看>>
2018.3.20
查看>>
2018.3.21
查看>>
2018.3.22
查看>>
2018.3.23
查看>>
A Game of Thrones(102)
查看>>
2018.4.29
查看>>
2018.4.30
查看>>
2018.4.31
查看>>
2018.4.32
查看>>
2018.4.33
查看>>
《python基础教程》答案(第一章)
查看>>
2018.4.34
查看>>
2018.4.35
查看>>