• Spring Boot Starter开发


    项目结构:

    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
    
  • 相关阅读:
    HDU 4763 Theme Section(KMP+枚举公共前后缀)
    HDU 3613 Best Reward(扩展KMP求前后缀回文串)
    HDU 3613 Best Reward(manacher求前、后缀回文串)
    扩展KMP模板
    Vue
    Vue
    css 文本换行 文本溢出隐藏用省略号表示剩下内容
    sublime 神一样的插件
    markdown
    css 居中布局
  • 原文地址:https://www.cnblogs.com/yinchh/p/13446312.html
Copyright © 2020-2023  润新知