一、注解
@SpringBootApplication
点开查看源码是由多个注解合成的注解,其中主要的注解有:
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan
三个关键的注解:
@ComponentScan 自动扫描加载进来的包,-----------可以扫描自动加载的bean
@EnableAutoConfiguration 启动自动配置
@SpringBootConfiguration 继承了@Configuration,所以可以使用@Configuration内容
@Configuration是spring提供的注解,@SpringBootConfiguration是springboot提供的注解。效果几乎一样,用哪个看自己的习惯。
二、pom配置
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 6 <groupId>com.springboot</groupId> 7 <artifactId>quick_start</artifactId> 8 <version>0.0.1-SNAPSHOT</version> 9 <packaging>jar</packaging> 10 11 <name>quick_start</name> 12 <url>http://maven.apache.org</url> 13 <description>Demo project for Spring Boot</description> 14 15 <!--<parent>--> 16 <!--<groupId>org.springframework.boot</groupId>--> 17 <!--<artifactId>spring-boot-starter-parent</artifactId>--> 18 <!--<version>2.0.2.RELEASE</version>--> 19 <!--<relativePath/> <!– lookup parent from repository –>--> 20 <!--</parent>--> 21 22 <properties> 23 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 24 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 25 <maven.compiler.source>1.8</maven.compiler.source> 26 <maven.compiler.target>1.8</maven.compiler.target> 27 <java.version>1.8</java.version> 28 </properties> 29 30 <dependencies> 31 <!--不使用parent方式进行依赖,需要scope和type设置--> 32 <dependency> 33 <groupId>org.springframework.boot</groupId> 34 <artifactId>spring-boot-dependencies</artifactId> 35 <version>2.0.2.RELEASE</version> 36 <scope>import</scope> 37 <type>pom</type> 38 </dependency> 39 40 41 <dependency> 42 <groupId>org.springframework.boot</groupId> 43 <artifactId>spring-boot-starter-web</artifactId> 44 </dependency> 45 46 <dependency> 47 <groupId>org.springframework.boot</groupId> 48 <artifactId>spring-boot-starter-test</artifactId> 49 <scope>test</scope> 50 </dependency> 51 </dependencies> 52 53 <build> 54 <plugins> 55 <plugin> 56 <groupId>org.springframework.boot</groupId> 57 <artifactId>spring-boot-maven-plugin</artifactId> 58 </plugin> 59 </plugins> 60 </build> 61 62 63 </project>