From 185a2c10144758a36e40ba4b909e53ae98d36e82 Mon Sep 17 00:00:00 2001 From: haoxiaoyong Date: Fri, 20 Mar 2020 17:56:02 +0800 Subject: [PATCH] Add AutoConfiguration --- .../cn/haoxy/distributed/JobApplication.java | 2 +- logs/xxl-job/xxl-job-admin.log.2020-01-11.zip | Bin 0 -> 1643 bytes okay-spring-boot-starter/pom.xml | 61 ++++++++++++++++++ .../okay/starter/annotation/EnableOkay.java | 27 ++++++++ .../okay/starter/config/OkayProperties.java | 52 +++++++++++++++ .../config/OkayStarterAutoConfiguration.java | 37 +++++++++++ .../haoxiaoyong/okay/starter/model/Okay.java | 49 ++++++++++++++ .../main/resources/META-INF/spring.factories | 2 + pom.xml | 1 + .../security/config/TokenStoreConfig.java | 12 ++-- 10 files changed, 238 insertions(+), 5 deletions(-) create mode 100644 logs/xxl-job/xxl-job-admin.log.2020-01-11.zip create mode 100644 okay-spring-boot-starter/pom.xml create mode 100644 okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/annotation/EnableOkay.java create mode 100644 okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayProperties.java create mode 100644 okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayStarterAutoConfiguration.java create mode 100644 okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/model/Okay.java create mode 100644 okay-spring-boot-starter/src/main/resources/META-INF/spring.factories diff --git a/distributed-job/src/main/java/cn/haoxy/distributed/JobApplication.java b/distributed-job/src/main/java/cn/haoxy/distributed/JobApplication.java index 5617754..e156d44 100644 --- a/distributed-job/src/main/java/cn/haoxy/distributed/JobApplication.java +++ b/distributed-job/src/main/java/cn/haoxy/distributed/JobApplication.java @@ -12,6 +12,6 @@ @SpringBootApplication public class JobApplication { public static void main(String[] args) { - SpringApplication.run(JobApplication.class,args); + SpringApplication.run(JobApplication.class, args); } } diff --git a/logs/xxl-job/xxl-job-admin.log.2020-01-11.zip b/logs/xxl-job/xx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0Zcvu0Zg;wp1a1x89&Twydv?)>MctJxP` zZK=2`D{s1E3GTV5nvQzlz}l6m&NCnW)$%Nwvl%ASCEhF5?$ec9G5Ls}3QQ_QKUr#a z + + + 4.0.0 + + cn.haoxiaoyong.okay + okay-spring-boot-starter + 0.0.2-SNAPSHO + + + + org.springframework.boot + spring-boot-autoconfigure + 2.1.4.RELEASE + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + + + org.springframework.boot + spring-boot-dependencies + 2.1.4.RELEASE + pom + import + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.4.RELEASE + + + NONE + + + + + repackage + + + + + + + \ No newline at end of file diff --git a/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/annotation/EnableOkay.java b/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/annotation/EnableOkay.java new file mode 100644 index 0000000..3545d5e --- /dev/null +++ b/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/annotation/EnableOkay.java @@ -0,0 +1,27 @@ +package cn.haoxiaoyong.okay.starter.annotation; + +import cn.haoxiaoyong.okay.starter.config.OkayProperties; +import cn.haoxiaoyong.okay.starter.config.OkayStarterAutoConfiguration; +import cn.haoxiaoyong.okay.starter.model.Okay; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.*; + +/** + * @author haoxiaoyong on 2020/3/20 下午 4:05 + * e-mail: hxyHelloWorld@163.com + * github: https://github.com/haoxiaoyong1014 + * Blog: www.haoxiaoyong.cn + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@EnableConfigurationProperties(OkayProperties.class) +@ConditionalOnWebApplication +@Import(OkayStarterAutoConfiguration.class) +public @interface EnableOkay { + +} diff --git a/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayProperties.java b/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayProperties.java new file mode 100644 index 0000000..0764d23 --- /dev/null +++ b/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayProperties.java @@ -0,0 +1,52 @@ +package cn.haoxiaoyong.okay.starter.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * @author haoxiaoyong on 2020/3/20 上午 11:04 + * e-mail: hxyHelloWorld@163.com + * github: https://github.com/haoxiaoyong1014 + * Blog: www.haoxiaoyong.cn + */ +@ConfigurationProperties(prefix = "okay.config") +public class OkayProperties { + + private String platform; + + private String channel; + + private Boolean enable; + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getChannel() { + return channel; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public Boolean getEnable() { + return enable; + } + + public void setEnable(Boolean enable) { + this.enable = enable; + } + + @Override + public String toString() { + return "OkayProperties{" + + "platform='" + platform + '\'' + + ", channel='" + channel + '\'' + + ", enable=" + enable + + '}'; + } +} diff --git a/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayStarterAutoConfiguration.java b/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayStarterAutoConfiguration.java new file mode 100644 index 0000000..ec0a2e1 --- /dev/null +++ b/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayStarterAutoConfiguration.java @@ -0,0 +1,37 @@ +package cn.haoxiaoyong.okay.starter.config; + +import cn.haoxiaoyong.okay.starter.model.Okay; +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.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author haoxiaoyong on 2020/3/20 上午 10:48 + * e-mail: hxyHelloWorld@163.com + * github: https://github.com/haoxiaoyong1014 + * Blog: www.haoxiaoyong.cn + */ +@Configuration +@EnableConfigurationProperties(OkayProperties.class) +@ConditionalOnClass(Okay.class) +@ConditionalOnWebApplication +public class OkayStarterAutoConfiguration { + + /** + * 当存在okay.config.enable=true的配置时,这个Okay bean才生效 + */ + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty(prefix = "okay.config", name = "enable", havingValue = "true") + public Okay defaultStudent(OkayProperties okayProperties) { + Okay okay = new Okay(); + okay.setPlatform(okayProperties.getPlatform()); + okay.setChannel(okayProperties.getChannel()); + okay.setEnable(okayProperties.getEnable()); + return okay; + } +} diff --git a/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/model/Okay.java b/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/model/Okay.java new file mode 100644 index 0000000..85895b4 --- /dev/null +++ b/okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/model/Okay.java @@ -0,0 +1,49 @@ +package cn.haoxiaoyong.okay.starter.model; + +/** + * @author haoxiaoyong on 2020/3/20 下午 1:27 + * e-mail: hxyHelloWorld@163.com + * github: https://github.com/haoxiaoyong1014 + * Blog: www.haoxiaoyong.cn + */ +public class Okay { + + private String platform; + + private String channel; + + private Boolean enable; + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getChannel() { + return channel; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public Boolean getEnable() { + return enable; + } + + public void setEnable(Boolean enable) { + this.enable = enable; + } + + @Override + public String toString() { + return "Okay{" + + "platform='" + platform + '\'' + + ", channel='" + channel + '\'' + + ", enable=" + enable + + '}'; + } +} diff --git a/okay-spring-boot-starter/src/main/resources/META-INF/spring.factories b/okay-spring-boot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..a8fd9db --- /dev/null +++ b/okay-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + cn.haoxiaoyong.okay.starter.config.OkayStarterAutoConfiguration \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5d74d8a..a6eb2b2 100644 --- a/pom.xml +++ b/pom.xml @@ -32,5 +32,6 @@ springboot-idempotent distributed-job mybatis-plus-example + okay-spring-boot-starter \ No newline at end of file diff --git a/springboot-oauth2-authorization-server/src/main/java/cn/merryyou/security/config/TokenStoreConfig.java b/springboot-oauth2-authorization-server/src/main/java/cn/merryyou/security/config/TokenStoreConfig.java index 0f82569..f29492c 100644 --- a/springboot-oauth2-authorization-server/src/main/java/cn/merryyou/security/config/TokenStoreConfig.java +++ b/springboot-oauth2-authorization-server/src/main/java/cn/merryyou/security/config/TokenStoreConfig.java @@ -30,6 +30,7 @@ public class TokenStoreConfig { /** * 用于存放token + * * @return */ @Bean @@ -43,26 +44,28 @@ public TokenStore redisTokenStore() { */ @Configuration @ConditionalOnProperty(prefix = "merryyou.security.oauth2", name = "storeType", havingValue = "jwt", matchIfMissing = true) - public static class JwtTokenCofnig{ + public static class JwtTokenCofnig { @Autowired private OAuth2Properties oAuth2Properties; /** * 使用jwtTokenStore存储token + * * @return */ @Bean - public TokenStore jwtTokenStore(){ + public TokenStore jwtTokenStore() { return new JwtTokenStore(jwtAccessTokenConverter()); } /** * 用于生成jwt + * * @return */ @Bean - public JwtAccessTokenConverter jwtAccessTokenConverter(){ + public JwtAccessTokenConverter jwtAccessTokenConverter() { JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter(); accessTokenConverter.setSigningKey(oAuth2Properties.getJwtSigningKey());//生成签名的key return accessTokenConverter; @@ -70,11 +73,12 @@ public JwtAccessTokenConverter jwtAccessTokenConverter(){ /** * 用于扩展JWT + * * @return */ @Bean @ConditionalOnMissingBean(name = "jwtTokenEnhancer") - public TokenEnhancer jwtTokenEnhancer(){ + public TokenEnhancer jwtTokenEnhancer() { return new MerryyouJwtTokenEnhancer(); }