• 准备环境
    sts jdk1.8 maven3.5
  • 步骤
    1. 创建maven工程
    2. 更改工程jdk版本
      <properties>
      <!-- java版本 -->
      <java.version>1.8</java.version>
      <!-- 编译时的编码 -->
      <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
      </properties>
      <build>
      <plugins>
         <plugin>
             <artifactId>maven-compiler-plugin</artifactId>
             <configuration>
                 <source>${java.version}</source>
                 <target>${java.version}</target>
                 <encoding>${maven.compiler.encoding}</encoding>
             </configuration>
         </plugin>
      </plugins>
      </build>
    3. 引入spring boot 父类
      <!-- 引入父类更好的规范各个依赖的version -->
      <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.0.RELEASE</version>
      </parent>
    4. 引入spring boot 的依赖
      <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter</artifactId>
      </dependency>
      </dependencies>
    5. spring boot 常用配置讲解

@SpringBootApplication 主配置注解(一般放在跟类)
@Bean 在spring 容器声明bean
@ComponentScan 指定扫描包
@Configuration 指定该类为配置类
@ImportResource 引入外部xml(最好指定 classpath:)

  1. spring boot 配置文

spring boot 配置文件 支持.properties 和 .yml 两种文件方式
分别默认加载 application为名字的文件
@PropertySource 加载.properties文件(最好指定 classpath:)
@ConfigurationProperties yml除@Value值的其他配置方式