最简单的springBoot应用
package com.louis.test;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class Run { public static void main(String[] args) { SpringApplication.run(Run.class, args); }}
1、@SpringBootApplication背后的秘密
@SpringBootApplication是一个“三体”结构,实际上是一个复合Annotation:
但主要的是这三个Annotation:
@Configuration
@EnableAutoConfiguration
@ComponentScan
所以上面的代码与下面的代码是等价的
package com.louis.test;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;@Configuration@EnableAutoConfiguration@ComponentScanpublic class Run { public static void main(String[] args) { SpringApplication.run(Run.class, args); }}
@Configuration
DemoApplication其实就是一个标准的Standalone类型的java程序的main函数启动类,没有什么特殊的
而@Configuration标注的DemoConfiguration定义其实也是一个普通的JavaConfig形式的IOC容器配置类
@EnableAutoConfiguration
@ComponentScan