forked from haoxiaoyong1014/springboot-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71bb1a3
commit 185a2c1
Showing
10 changed files
with
238 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
27 changes: 27 additions & 0 deletions
27
...-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/annotation/EnableOkay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + | ||
'}'; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...tarter/src/main/java/cn/haoxiaoyong/okay/starter/config/OkayStarterAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
okay-spring-boot-starter/src/main/java/cn/haoxiaoyong/okay/starter/model/Okay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + | ||
'}'; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
okay-spring-boot-starter/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters