Skip to content

Commit

Permalink
Add AutoConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxiaoyong1014 committed Mar 20, 2020
1 parent 71bb1a3 commit 185a2c1
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
@SpringBootApplication
public class JobApplication {
public static void main(String[] args) {
SpringApplication.run(JobApplication.class,args);
SpringApplication.run(JobApplication.class, args);
}
}
Binary file added logs/xxl-job/xxl-job-admin.log.2020-01-11.zip
Binary file not shown.
61 changes: 61 additions & 0 deletions okay-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/>
</parent>-->
<modelVersion>4.0.0</modelVersion>

<groupId>cn.haoxiaoyong.okay</groupId>
<artifactId>okay-spring-boot-starter</artifactId>
<version>0.0.2-SNAPSHO</version>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<dependencyManagement>
<!-- 我们是基于Springboot的应用 -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.4.RELEASE</version>
<configuration>
<!-- <mainClass>${start-class}</mainClass>-->
<layout>NONE</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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: [email protected]
* 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 {

}
Original file line number Diff line number Diff line change
@@ -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: [email protected]
* 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 +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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: [email protected]
* 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cn.haoxiaoyong.okay.starter.model;

/**
* @author haoxiaoyong on 2020/3/20 下午 1:27
* e-mail: [email protected]
* 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 +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.haoxiaoyong.okay.starter.config.OkayStarterAutoConfiguration
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
<module>springboot-idempotent</module>
<module>distributed-job</module>
<module>mybatis-plus-example</module>
<module>okay-spring-boot-starter</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class TokenStoreConfig {

/**
* 用于存放token
*
* @return
*/
@Bean
Expand All @@ -43,38 +44,41 @@ 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;
}

/**
* 用于扩展JWT
*
* @return
*/
@Bean
@ConditionalOnMissingBean(name = "jwtTokenEnhancer")
public TokenEnhancer jwtTokenEnhancer(){
public TokenEnhancer jwtTokenEnhancer() {
return new MerryyouJwtTokenEnhancer();
}

Expand Down

0 comments on commit 185a2c1

Please sign in to comment.