Skip to content

Commit 4b71fe9

Browse files
committed
myapp-spring-boot-starter
1 parent 64bfaa3 commit 4b71fe9

File tree

13 files changed

+306
-0
lines changed

13 files changed

+306
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.0.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>net.codingme.starter</groupId>
12+
<artifactId>myapp-spring-boot-autoconfigure</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>myapp-spring-boot-autoconfigure</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter</artifactId>
25+
</dependency>
26+
</dependencies>
27+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package net.codingme.starter;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
5+
/**
6+
* <p>
7+
*
8+
* @Author niujinpeng
9+
* @Date 2019/10/29 23:51
10+
*/
11+
@ConfigurationProperties(prefix = "myapp.hello")
12+
public class HelloProperties {
13+
14+
private String suffix;
15+
16+
public String getSuffix() {
17+
return suffix;
18+
}
19+
20+
public void setSuffix(String suffix) {
21+
this.suffix = suffix;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.codingme.starter;
2+
3+
/**
4+
* <p>
5+
*
6+
* @Author niujinpeng
7+
* @Date 2019/10/29 23:51
8+
*/
9+
public class HelloService {
10+
11+
HelloProperties helloProperties;
12+
13+
public String sayHello(String name) {
14+
return "Hello " + name + "," + helloProperties.getSuffix();
15+
}
16+
17+
public HelloProperties getHelloProperties() {
18+
return helloProperties;
19+
}
20+
21+
public void setHelloProperties(HelloProperties helloProperties) {
22+
this.helloProperties = helloProperties;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.codingme.starter;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
5+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
/**
10+
* <p>
11+
*
12+
* @Author niujinpeng
13+
* @Date 2019/10/30 8:18
14+
*/
15+
16+
/**
17+
* web应用才生效
18+
*/
19+
@ConditionalOnWebApplication
20+
/**
21+
* 让属性文件生效
22+
*/
23+
@EnableConfigurationProperties(HelloProperties.class)
24+
/***
25+
* 声明是一个配置类
26+
*/
27+
@Configuration
28+
public class HelloServiceAutoConfiguration {
29+
30+
@Autowired
31+
private HelloProperties helloProperties;
32+
33+
@Bean
34+
public HelloService helloService() {
35+
HelloService helloService = new HelloService();
36+
helloService.setHelloProperties(helloProperties);
37+
return helloService;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Auto Configure
2+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
3+
net.codingme.starter.HelloServiceAutoConfiguration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.0.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>net.codingme.starter</groupId>
12+
<artifactId>myapp-spring-boot-starter-test</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>myapp-spring-boot-starter-test</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
27+
<!-- 引入自己的 starter -->
28+
<dependency>
29+
<groupId>net.codingme.starter</groupId>
30+
<artifactId>myapp-spring-boot-starter</artifactId>
31+
<version>1.0-SNAPSHOT</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-test</artifactId>
37+
<scope>test</scope>
38+
<exclusions>
39+
<exclusion>
40+
<groupId>org.junit.vintage</groupId>
41+
<artifactId>junit-vintage-engine</artifactId>
42+
</exclusion>
43+
</exclusions>
44+
</dependency>
45+
</dependencies>
46+
47+
<build>
48+
<plugins>
49+
<plugin>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-maven-plugin</artifactId>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
56+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package net.codingme.starter;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class MyappSpringBootStarterTestApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(MyappSpringBootStarterTestApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.codingme.starter.controller;
2+
3+
import net.codingme.starter.HelloService;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
/**
9+
* <p>
10+
*
11+
* @Author niujinpeng
12+
* @Date 2019/10/30 8:31
13+
*/
14+
@RestController
15+
public class HelloController {
16+
17+
@Autowired
18+
HelloService helloService;
19+
20+
@GetMapping("/hello")
21+
public String sayHello(String name) {
22+
return helloService.sayHello(name);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server.port=8080
2+
myapp.hello.suffix=\u65E9\u4E0A\u597D
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.codingme.starter;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class MyappSpringBootStarterTestApplicationTests {
8+
9+
@Test
10+
void contextLoads() {}
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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>net.codingme.starter</groupId>
8+
<artifactId>myapp-spring-boot-starter</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<!-- 启动器 -->
11+
<dependencies>
12+
<!-- 引入自动配置项目 -->
13+
<dependency>
14+
<groupId>net.codingme.starter</groupId>
15+
<artifactId>myapp-spring-boot-autoconfigure</artifactId>
16+
<version>0.0.1-SNAPSHOT</version>
17+
</dependency>
18+
</dependencies>
19+
20+
21+
</project>

0 commit comments

Comments
 (0)