/**
-
@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 = helloProper
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
ties;
}
}
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”>
4.0.0
com.springboot
spring-boot-starter-autoconfigurer
0.0.1-SNAPSHOT
jar
spring-boot-starter-autoconfigurer
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.4.RELEASE
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
org.springframework.boot
spring-boot-starter
(2) springbootstarter
启动器比较简单,只有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”>
4.0.0
wms
springboot-starter
1.0-SNAPSHOT
com.springboot
spring-boot-starter-autoconfigurer
0.0.1-SNAPSHOT
5、 测试,新建springboot项目,pom文件中引入启动器
springboot
springboot-starter
1.0-SNAPSHOT
application.properties添加配置项
springboot.hello.name=chenzz
测试controller:
package com.springboot.teststarter;
import com.wms.starter.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;