springBoot配置文件:
1)pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.st</groupId>
<artifactId>springBootDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springBootDemo</name>
<properties>
<!-- 输入编码 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 输出编码 -->
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!--
设置maven-compiler-plugin插件使用的jdk版本
如果不指明版本,maven项目会用maven-compiler-plugin默认的jdk版本来进行编译,
就容易出现版本不匹配的问题,导致编译不通过
-->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- jdk版本-->
<java.version>1.8</java.version>
</properties>
<!-- 包括了待继承的父工程所需要的信息 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<!--springboot启动类,核心类-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- 引入springMVC -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--<version>2.0.6.RELEASE</version>-->
</plugin>
</plugins>
</build>
</project>
2)resource中的application.yml文件:
注意:yml文件要严格缩进;每次缩进空两个空格;不能用Tab键缩进(会报错)
server:
# 服务段口号
port: 8080
# 服务名称
servlet:
context-path: /bootDemo
3)Application.java
Application是springBoot项目的启动类,启动类要在其他类的上一级目录
图示启动类为App
package com.st;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App
{
public static void main( String[] args )
{
SpringApplication.run(App.class);//启动springBoot项目
}
}