springboot官方文档:官方文档
1. Maven Spring Boot搭建
首先在pom文件中添加两个maven依赖
<!-- 在maven工程中加入SpringBoot 内核支持
(标准搭建应将springboot的核心支付放入到parent标签中,
而不应该放在dependencies标签中,这样保证后续的springboot分支maven包,
都基于parent标签中的核心来延展)-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<type>pom</type>
</dependency>
<!--上述配置需要修改优化-->
<!-- 在maven工程中加入SpringBoot web工程的支持 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
修改后的pom基础配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<dependencies>
<!-- 在maven工程中加入SpringBoot web工程的支持 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
</dependencies>
2.创建SpringBoot项目入口
/**
1. 该类需要放在根包下,@SpringBootApplication 中会自动扫描该包下的所有spring注解配置,如若不放在
2. 根包下,会导致扫码扫码不了。解决方案是手动配置一下扫描包路径,但是显然没必要。根据行业习惯,都是放
3. 在根包下面的。
*/
@SpringBootApplication
public class MySpringbootApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MySpringbootApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MySpringbootApplication.class);
}
}
- 编写yml配置文件
server:
port: 8080 # tomcat启动端口号
tomcat:
uri-encoding: utf-8
- 整合mybatis
在pom.xml文件中添加maven包的支持
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.8</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>