From 1d0bc4cc16c98eea389be0da6cac200b57c135d1 Mon Sep 17 00:00:00 2001 From: yidao620 Date: Wed, 28 Feb 2018 12:19:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=A0=81=E7=A4=BA?= =?UTF-8?q?=E4=BE=8Bspringboot-starter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- springboot-starter/.gitignore | 14 ++++ springboot-starter/LICENSE | 20 +++++ springboot-starter/README.md | 9 ++ springboot-starter/pom.xml | 83 +++++++++++++++++++ .../com/xncoding/starter/Application.java | 12 +++ .../starter/config/ExampleAutoConfigure.java | 38 +++++++++ .../config/ExampleServiceProperties.java | 32 +++++++ .../starter/service/ExampleService.java | 22 +++++ .../main/resources/META-INF/spring.factories | 2 + 9 files changed, 232 insertions(+) create mode 100644 springboot-starter/.gitignore create mode 100644 springboot-starter/LICENSE create mode 100644 springboot-starter/README.md create mode 100644 springboot-starter/pom.xml create mode 100644 springboot-starter/src/main/java/com/xncoding/starter/Application.java create mode 100644 springboot-starter/src/main/java/com/xncoding/starter/config/ExampleAutoConfigure.java create mode 100644 springboot-starter/src/main/java/com/xncoding/starter/config/ExampleServiceProperties.java create mode 100644 springboot-starter/src/main/java/com/xncoding/starter/service/ExampleService.java create mode 100644 springboot-starter/src/main/resources/META-INF/spring.factories diff --git a/springboot-starter/.gitignore b/springboot-starter/.gitignore new file mode 100644 index 0000000..1e3c5bb --- /dev/null +++ b/springboot-starter/.gitignore @@ -0,0 +1,14 @@ +# 此为注释– 将被Git 忽略 +# /结尾表示是目录,忽略目录和目录下的所有件 +# /开头表示根目录,否则是.gitignore的相对目录 +# !开头表示反选 +.idea/ +target/ +*.iml +*.ipr +*.iws +*.log +.svn/ +.project +rebel.xml +.rebel-remote.xml.* diff --git a/springboot-starter/LICENSE b/springboot-starter/LICENSE new file mode 100644 index 0000000..83cd47d --- /dev/null +++ b/springboot-starter/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2018 Xiong Neng + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/springboot-starter/README.md b/springboot-starter/README.md new file mode 100644 index 0000000..0da2249 --- /dev/null +++ b/springboot-starter/README.md @@ -0,0 +1,9 @@ +## 教你自己写starter + +编写自己的starter + +## 许可证 + +Copyright (c) 2018 Xiong Neng + +基于 MIT 协议发布: diff --git a/springboot-starter/pom.xml b/springboot-starter/pom.xml new file mode 100644 index 0000000..6b56a5f --- /dev/null +++ b/springboot-starter/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + com.xncoding + springboot-starter + 1.0.0-SNAPSHOT + jar + + springboot-starter + 自己写starter + + + org.springframework.boot + spring-boot-starter-parent + 1.5.9.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.springframework.boot + spring-boot-autoconfigure + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.20 + + true + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + + src/main/resources + + + src/main/java + + **/*.xml + + + + + + \ No newline at end of file diff --git a/springboot-starter/src/main/java/com/xncoding/starter/Application.java b/springboot-starter/src/main/java/com/xncoding/starter/Application.java new file mode 100644 index 0000000..44067b0 --- /dev/null +++ b/springboot-starter/src/main/java/com/xncoding/starter/Application.java @@ -0,0 +1,12 @@ +package com.xncoding.starter; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/springboot-starter/src/main/java/com/xncoding/starter/config/ExampleAutoConfigure.java b/springboot-starter/src/main/java/com/xncoding/starter/config/ExampleAutoConfigure.java new file mode 100644 index 0000000..307c721 --- /dev/null +++ b/springboot-starter/src/main/java/com/xncoding/starter/config/ExampleAutoConfigure.java @@ -0,0 +1,38 @@ +package com.xncoding.starter.config; + +import com.xncoding.starter.service.ExampleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * ExampleAutoConfigure + * + * @author XiongNeng + * @version 1.0 + * @since 2018/2/28 + */ +@Configuration +@ConditionalOnClass(ExampleService.class) +@EnableConfigurationProperties(ExampleServiceProperties.class) +public class ExampleAutoConfigure { + + private final ExampleServiceProperties properties; + + @Autowired + public ExampleAutoConfigure(ExampleServiceProperties properties) { + this.properties = properties; + } + + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty(prefix = "example.service", value = "enabled",havingValue = "true") + ExampleService exampleService (){ + return new ExampleService(properties.getPrefix(),properties.getSuffix()); + } + +} diff --git a/springboot-starter/src/main/java/com/xncoding/starter/config/ExampleServiceProperties.java b/springboot-starter/src/main/java/com/xncoding/starter/config/ExampleServiceProperties.java new file mode 100644 index 0000000..e6da5ef --- /dev/null +++ b/springboot-starter/src/main/java/com/xncoding/starter/config/ExampleServiceProperties.java @@ -0,0 +1,32 @@ +package com.xncoding.starter.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * ExampleServiceProperties + * + * @author XiongNeng + * @version 1.0 + * @since 2018/2/28 + */ +@ConfigurationProperties("example.service") +public class ExampleServiceProperties { + private String prefix; + private String suffix; + + public String getPrefix() { + return prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(String suffix) { + this.suffix = suffix; + } +} diff --git a/springboot-starter/src/main/java/com/xncoding/starter/service/ExampleService.java b/springboot-starter/src/main/java/com/xncoding/starter/service/ExampleService.java new file mode 100644 index 0000000..f81aa3b --- /dev/null +++ b/springboot-starter/src/main/java/com/xncoding/starter/service/ExampleService.java @@ -0,0 +1,22 @@ +package com.xncoding.starter.service; + +/** + * ExampleService + * + * @author XiongNeng + * @version 1.0 + * @since 2018/2/28 + */ +public class ExampleService { + + private String prefix; + private String suffix; + + public ExampleService(String prefix, String suffix) { + this.prefix = prefix; + this.suffix = suffix; + } + public String wrap(String word) { + return prefix + word + suffix; + } +} diff --git a/springboot-starter/src/main/resources/META-INF/spring.factories b/springboot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..a16e1ce --- /dev/null +++ b/springboot-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +com.xncoding.starter.config.ExampleAutoConfigure \ No newline at end of file