一、starter的工作原理
==============
1、springboot在启动时扫描项目所依赖的jar包,寻找包含搜spring.factories文件的jar包
2、根据spring.factories配置加载AutoConfiure类
3、根据@Conditional注解的条件,进行自动配置并将Bean注入spring context
二、自定义starter
============
1、IDEA创建一个empty project
2、添加两个module,一个是自动配置(maven工程),一个是启动器(springboot工程),启动器依赖自动配置。
3、项目结构
4、内部代码
(1)spring-boot-starter-autoconfigurer module
package com.springboot.starter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author:素小暖
* @date:2020/2/9
* @desc:
*/
@Configuration
@EnableConfigurationProperties(HelloProperties.class)
public class HelloAuto {
@Autowired
HelloProperties helloProperties;
@Bean
public HelloService helloService() {
HelloService helloService = new HelloService();
helloService.setHelloProperties(helloProperties);
return helloService;
}
}
package com.springboot.starter;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
-
@author:素小暖
-
@date:2020/2/9
-
@desc:
*/
@ConfigurationProperties(prefix = “springboot.hello”)
public class HelloProperties {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.springboot.starter;
/**
* @author:素小暖
* @date:2020/2/9
* @desc:
*/
public class HelloService {
HelloProperties helloProperties;
public String hello() {
return "hello" + helloProperties.getName();
}
public HelloProperties getHelloProperties() {
return helloProperties;
}
public void setHelloProperties(HelloProperties helloProperties) {
this.helloProperties = helloProperties;
}
}
```
spring.properties文件
```
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.springboot.starter.HelloAuto
```
POM文件
```
<?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.springboot</groupId>
<artifactId>spring-boot-starter-autoconfigurer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot-starter-autoconfigurer</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
### 最后在出来放一波福利吧!希望可以帮助到大家!
> **[CodeChina开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频】](https://codechina.youkuaiyun.com/m0_60958482/java-p7)**
千千万万要记得:多刷题!!多刷题!!
之前算法是我的硬伤,后面硬啃了好长一段时间才补回来,算法才是程序员的灵魂!!!!
篇幅有限,以下只能截图分享部分的资源!!
(1)多线程(这里以多线程为代表,其实整理了一本JAVA核心架构笔记集)

(2)刷的算法题(还有左神的算法笔记)

(3)面经+真题解析+对应的相关笔记(很全面)

(4)视频学习(部分)
> ps:当你觉得学不进或者累了的时候,视频是个不错的选择
其实以上我所分享的所有东西,有需要的话我这边可以免费分享给大家
源!!
(1)多线程(这里以多线程为代表,其实整理了一本JAVA核心架构笔记集)
[外链图片转存中...(img-RfDIvh49-1630925100712)]
(2)刷的算法题(还有左神的算法笔记)
[外链图片转存中...(img-nROgOGvt-1630925100714)]
(3)面经+真题解析+对应的相关笔记(很全面)
[外链图片转存中...(img-ca3T7M7F-1630925100715)]
(4)视频学习(部分)
> ps:当你觉得学不进或者累了的时候,视频是个不错的选择
其实以上我所分享的所有东西,有需要的话我这边可以免费分享给大家
在这里,最后只一句话:祝大家offer拿到手软!!