Skip to content

Commit 1d0bc4c

Browse files
committed
添加代码示例springboot-starter
1 parent e683c35 commit 1d0bc4c

File tree

9 files changed

+232
-0
lines changed

9 files changed

+232
-0
lines changed

springboot-starter/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 此为注释– 将被Git 忽略
2+
# /结尾表示是目录,忽略目录和目录下的所有件
3+
# /开头表示根目录,否则是.gitignore的相对目录
4+
# !开头表示反选
5+
.idea/
6+
target/
7+
*.iml
8+
*.ipr
9+
*.iws
10+
*.log
11+
.svn/
12+
.project
13+
rebel.xml
14+
.rebel-remote.xml.*

springboot-starter/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Xiong Neng
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

springboot-starter/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## 教你自己写starter
2+
3+
编写自己的starter
4+
5+
## 许可证
6+
7+
Copyright (c) 2018 Xiong Neng
8+
9+
基于 MIT 协议发布: <http://www.opensource.org/licenses/MIT>

springboot-starter/pom.xml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.xncoding</groupId>
8+
<artifactId>springboot-starter</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>springboot-starter</name>
13+
<description>自己写starter</description>
14+
15+
<parent>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-parent</artifactId>
18+
<version>1.5.9.RELEASE</version>
19+
<relativePath/>
20+
</parent>
21+
22+
<properties>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
25+
<java.version>1.8</java.version>
26+
</properties>
27+
28+
<dependencies>
29+
<!-- @ConfigurationProperties annotation processing (metadata for IDEs)
30+
生成spring-configuration-metadata.json类,需要引入此类-->
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-configuration-processor</artifactId>
34+
<optional>true</optional>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-autoconfigure</artifactId>
39+
</dependency>
40+
</dependencies>
41+
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-compiler-plugin</artifactId>
47+
<version>3.6.1</version>
48+
<configuration>
49+
<!--<proc>none</proc>-->
50+
<source>1.8</source>
51+
<target>1.8</target>
52+
</configuration>
53+
</plugin>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-surefire-plugin</artifactId>
57+
<version>2.20</version>
58+
<configuration>
59+
<skip>true</skip>
60+
</configuration>
61+
</plugin>
62+
<plugin>
63+
<groupId>org.springframework.boot</groupId>
64+
<artifactId>spring-boot-maven-plugin</artifactId>
65+
<executions>
66+
</executions>
67+
</plugin>
68+
</plugins>
69+
70+
<resources>
71+
<resource>
72+
<directory>src/main/resources</directory>
73+
</resource>
74+
<resource>
75+
<directory>src/main/java</directory>
76+
<includes>
77+
<include>**/*.xml</include>
78+
</includes>
79+
</resource>
80+
</resources>
81+
</build>
82+
83+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.xncoding.starter;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
public static void main(String[] args) {
9+
SpringApplication.run(Application.class, args);
10+
}
11+
12+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.xncoding.starter.config;
2+
3+
import com.xncoding.starter.service.ExampleService;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
6+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
7+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
8+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
12+
/**
13+
* ExampleAutoConfigure
14+
*
15+
* @author XiongNeng
16+
* @version 1.0
17+
* @since 2018/2/28
18+
*/
19+
@Configuration
20+
@ConditionalOnClass(ExampleService.class)
21+
@EnableConfigurationProperties(ExampleServiceProperties.class)
22+
public class ExampleAutoConfigure {
23+
24+
private final ExampleServiceProperties properties;
25+
26+
@Autowired
27+
public ExampleAutoConfigure(ExampleServiceProperties properties) {
28+
this.properties = properties;
29+
}
30+
31+
@Bean
32+
@ConditionalOnMissingBean
33+
@ConditionalOnProperty(prefix = "example.service", value = "enabled",havingValue = "true")
34+
ExampleService exampleService (){
35+
return new ExampleService(properties.getPrefix(),properties.getSuffix());
36+
}
37+
38+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.xncoding.starter.config;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
5+
/**
6+
* ExampleServiceProperties
7+
*
8+
* @author XiongNeng
9+
* @version 1.0
10+
* @since 2018/2/28
11+
*/
12+
@ConfigurationProperties("example.service")
13+
public class ExampleServiceProperties {
14+
private String prefix;
15+
private String suffix;
16+
17+
public String getPrefix() {
18+
return prefix;
19+
}
20+
21+
public void setPrefix(String prefix) {
22+
this.prefix = prefix;
23+
}
24+
25+
public String getSuffix() {
26+
return suffix;
27+
}
28+
29+
public void setSuffix(String suffix) {
30+
this.suffix = suffix;
31+
}
32+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.xncoding.starter.service;
2+
3+
/**
4+
* ExampleService
5+
*
6+
* @author XiongNeng
7+
* @version 1.0
8+
* @since 2018/2/28
9+
*/
10+
public class ExampleService {
11+
12+
private String prefix;
13+
private String suffix;
14+
15+
public ExampleService(String prefix, String suffix) {
16+
this.prefix = prefix;
17+
this.suffix = suffix;
18+
}
19+
public String wrap(String word) {
20+
return prefix + word + suffix;
21+
}
22+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2+
com.xncoding.starter.config.ExampleAutoConfigure

0 commit comments

Comments
 (0)