# qyt-spring-boot-starter
**Repository Path**: qytcoding/qyt-spring-boot-starter
## Basic Information
- **Project Name**: qyt-spring-boot-starter
- **Description**: 自定义的springboot自动启动包
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-12-26
- **Last Updated**: 2021-12-26
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## 自定义生成springboot启动器
创建工程:
父类功能:qyt-springbot-starter
子模块:qyt-spring-boot-autoconfigure、qyt-spring-boot-starter
1、pom的内容
qyt-springbot-starter
```bash
        org.springframework.boot
        spring-boot-starter-parent
        2.1.17.RELEASE
        
	
		org.springframework.boot
		spring-boot-starter
	
```
qyt-spring-boot-autoconfigure
```bash
    qyt-springboot-starter
    com.qyt
    1.0-SNAPSHOT
4.0.0
qyt-spring-boot-autoconfigure
    org.springframework.boot
    spring-boot-starter-web
    org.springframework.boot
    spring-boot-configuration-processor
    true
```
qyt-spring-boot-starter
```bash
    
        qyt-springboot-starter
        com.qyt
        1.0-SNAPSHOT
    
    4.0.0
    qyt-spring-boot-strarter
    
        启动器(starter)是一个空的jar文件
        仅仅提供辅助性作用
    
    
        
            com.qyt
            qyt-spring-boot-autoconfigure
            1.0-SNAPSHOT
        
    
```
2、开始编写内容
**qyt-springbot-starter和qyt-spring-boot-starter工程没有内容就只用看pom的依赖就可以了**
```bash
/**
 * 自动配置类
 * 给web应用添加一个首页
 */
@Configuration
//加载配置文件,因为可能没有扫描所以要使用该方法手动引用
@EnableConfigurationProperties({HelloProperties.class})
//必须要有这个不然不生效
@ConditionalOnProperty(value = "qyt.hello.name")
public class HelloAutoConfiguration {
    @Autowired
    private HelloProperties helloProperties;
    @Bean
    public HelloController helloController(){
        return new HelloController(helloProperties);
    }
}
```
```bash
@RestController
public class HelloController {
    @Autowired
    HelloProperties helloProperties;
    public HelloController(){
    }
    public HelloController(HelloProperties helloProperties){
            this.helloProperties = helloProperties;
    }
    @GetMapping("/")
    public String getIndex(){
        return " i am  " + helloProperties.getName();
    }
}
```
```bash
@ConfigurationProperties("qyt.hello")
public class HelloProperties {
    private String name ;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
```
在resource目录下创建META-INF文件
创建spring-factories
```bash
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.starter.qyt.HelloAutoConfiguration
```