创建一个自定义的springboot-starter

2020-08-18  本文已影响0人  绝对熙俊

创建一个新的Springboot项目

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
</parent>
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
</dependencies>
@ConfigurationProperties(prefix = "za.fcp.common.share")
public class ShareProperties {
    /**
     * 是否启用,默认启用
     */
    private Boolean enable = true;
    public Boolean getEnable() {
        return enable;
    }
    public void setEnable(Boolean enable) {
        this.enable = enable;
    }
}
public class ShareComponent {

    private boolean enable;

    public ShareComponent(boolean enable) {
        this.enable = enable;
    }

    public boolean enable() {
        return this.enable;
    }
}
@Configuration
@EnableConfigurationProperties(ShareProperties.class)
@ConditionalOnProperty(
        prefix = "za.fcp.common.util",
        name = "enable",
        havingValue = "true"
)
public class ShareConfig {

    @Autowired
    private ShareProperties shareProperties;

    @Bean(name = "shareComponent")
    public ShareComponent shareComponent() {
        return new ShareComponent(shareProperties.getEnable());
    }

}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.zhongan.fcp.common.share.configuration.ShareConfig
上一篇下一篇

猜你喜欢

热点阅读