首页 > 编程语言 > 详细

Spring Boot Starter开发

时间:2020-08-06 15:06:15      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:miss   分享图片   tor   ice   ESS   pri   

项目结构:
技术分享图片

pom.xml

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>2.2.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <version>2.2.7.RELEASE</version>
            <optional>true</optional>
        </dependency>

UserProperties.java

@Data
@ConfigurationProperties(prefix = "com.run.user")
public class UserProperties {
    private int id = 1;
    private String name = "ych";
    private String sex = "男";
}

UserService.java

public class UserService {
    private UserProperties userProperties;

    public UserService(UserProperties prop) {
        this.userProperties = prop;
    }

    public void say() {
        System.out.println(userProperties.toString());
    }
}

UserServiceAutoConfiguration.java

@Configuration
@EnableConfigurationProperties(UserProperties.class)
public class UserServiceAutoConfiguration {
    @Autowired
    private UserProperties userProperties;

    @Bean
    @ConditionalOnMissingBean(UserService.class)
    public UserService userService() {
        UserService userService = new UserService(userProperties);
        return userService;
    }
}

spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=    com.run.UserServiceAutoConfiguration

Spring Boot Starter开发

标签:miss   分享图片   tor   ice   ESS   pri   

原文:https://www.cnblogs.com/yinchh/p/13446312.html

(0)
(0)
   
举报
评论 一句话评论(0
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号