Spring Boot学习(二)
基于Spring Boot创建的maven项目

1、application.properties或者application.yml:全局配置文件
作用:主要用来配置数据库连接、日志相关配置等
推荐使用yml
注意:使用.yml时,属性名的值和冒号中间必须有空格,如name: 123正确,name:123就是错的。


2、DemoApplication.javamain方法:应用入口
@SpringBootApplication:核心注解,主要目的是开启自动配置
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
3、pom.xml
Spring boot的项目必须要将parent设置为spring boot的parent,该parent包含了大量默认的配置。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Spring Boot的web支持
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Spring Boot的测试
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
Spring Boot的maven插件
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
4、静态资源访问
目录名需符合如下规则:
- /static
- /public
- /resources
- /META-INF/resources

浙公网安备 33010602011771号