浦东网站建设价格天津百度搜索排名优化
SpringBoot2知识点记录
- 1.SpringBoot2基础入门
- 1.1 环境要求
- 1.1.1 maven设置
- 1.2 第一个程序 HelloWorld
- 1.2.1 创建maven工程
- 1.2.2 引入依赖
- 1.2.3 创建主程序
- 1.2.4 编写业务
- 1.2.5 测试
- 1.2.6 简化配置
- 1.2.7 简化部署
- 1.3 自动装配
- 1.3.1 SpringBoot特点
- 1.3.1.1 依赖管理
- 1.3.1.2 自动装配
- 1.3.2 容器功能
- 1.3.2.1 底层注解
- (1)@Configuration
- 1.3.2.2
- 1.3.2.3
- 1.3.2.4
- 1.3.3 自动装配原理入门
- 1.3.4 开发小技巧
- 2.SpringBoot2核心功能
- 3.
1.SpringBoot2基础入门
1.1 环境要求
- Java 8 (JDK1.8)
- Maven 3.3+
- idea
1.1.1 maven设置
配置maven的阿里云下载路径和java的jdk版本为1.8
<mirrors><mirror><id>nexus-aliyun</id><mirrorOf>central</mirrorOf><name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public</url></mirror></mirrors><profile><id>jdk-1.8</id><activation><activeByDefault>true</activeByDefault><jdk>1.8</jdk></activation><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></properties></profile></profiles>
1.2 第一个程序 HelloWorld
1.2.1 创建maven工程
1.2.2 引入依赖
pom.xml中导入依赖包
<!--导入SpringBoot 2.3.4版本--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.4.RELEASE</version></parent><dependencies><!--开发web场景模式的包--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>
1.2.3 创建主程序
package com.atguigu.boot;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** 主程序类* @SpringBootApplication:标识这是一个SpringBoot程序应用*/
@SpringBootApplication
public class MainApplication {public static void main(String[] args) {SpringApplication.run(MainApplication.class,args);}
}
1.2.4 编写业务
package com.atguigu.boot.controller;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@RequestMapping("/hello")public String handle01(){return "hello,SpringBoot2";}
}
1.2.5 测试
1.2.6 简化配置
SpringBoot简化了配置文件,所有的配置文件可以全部存放在application.properties文件中。
文件存放路径:src/main/resources/application.properties
#设置端口号
server.port=8080
1.2.7 简化部署
把项目打成jar包,直接在目标服务器执行即可。
<!--引入依赖,项目打包成jar包--><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
直接打包成jar包,可以在目标服务器上面执行打开。
注意:需要关闭cmd属性中的快捷编辑,否则会卡住项目执行。
1.3 自动装配
1.3.1 SpringBoot特点
1.3.1.1 依赖管理
父项目做资源来管理,存放了很多依赖的版本号,可以在pom.xml中引入的时候,不需要写过多的版本号。
1.3.1.2 自动装配
自动装配了很多常见的开发场景,不需要像SpringMVC一样整合起来需要配置很多东西。
1.3.2 容器功能
1.3.2.1 底层注解
(1)@Configuration
@Bean、@Component、@Controller、@Service、@Repository
@ComponentScan、@Import
@Conditional