# spring-boot-starter-hello **Repository Path**: specialcode/spring-boot-starter-hello ## Basic Information - **Project Name**: spring-boot-starter-hello - **Description**: 基于maven实现一个简单的starter pom组件 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-11-16 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # spring-boot-starter-hello #### Description 基于Maven项目构建的,简单实现一个spring-boot-starter的自动配置示例 #### Installation 使用`mvn clean install`命令安装至本地maven仓库 ### Usage 1. 在需要使用该 starter pom 的项目中,在pom文件中添加如下依赖: ``` com.vitamin spring-boot-starter-hello 0.0.1-SNAPSHOT ``` 2. 在配置文件 `application.properties`中添加如下配置: ``` hello.enabled=true #默认情况下,就是true。此处可省略。 hello.msg=vitamin #设置配置属性的值。可为任意值。 debug=true #开启Debug,方便观察是否被自动进行了配置。 ``` 3. 在项目中的具体使用方式如下: ``` @Autowired private HelloSerice helloService; ``` ### Example 新建Spring Boot项目,并新创建如下控制器。 ``` @RestController public class HelloController { @Autowired private HelloService helloService; @GetMapping("/say") public String sayHello() { return helloService.sayHello(); } } ``` 在浏览器中访问`http://localhost:8080/say`即可看到如下内容: ``` hello vitamin ``` 在启动控制中则会看到如下信息表示自动配置成功: ``` HelloServiceAutoConfiguration matched: - @ConditionalOnClass found required class 'com.vitamin.spring_boot_starter_hello.HelloService' (OnClassCondition) - @ConditionalOnProperty (hello.enabled) matched (OnPropertyCondition) ```