Skip to content

Commit 243a7e3

Browse files
author
lihengming
committed
Initial commit
0 parents  commit 243a7e3

File tree

6 files changed

+117
-0
lines changed

6 files changed

+117
-0
lines changed

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/

pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.example</groupId>
8+
<artifactId>example-spring-boot-starter</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<dependencies>
11+
<dependency>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-autoconfigure</artifactId>
14+
</dependency>
15+
</dependencies>
16+
<dependencyManagement>
17+
<dependencies>
18+
<dependency>
19+
<!-- Import dependency management from Spring Boot -->
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-dependencies</artifactId>
22+
<version>1.5.2.RELEASE</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
28+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.autocinfigure;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
5+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
6+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
@Configuration
12+
@ConditionalOnClass(ExampleService.class)
13+
@EnableConfigurationProperties(ExampleServiceProperties.class)
14+
public class ExampleAutoConfigure {
15+
16+
@Autowired
17+
private ExampleServiceProperties properties;
18+
19+
@Bean
20+
@ConditionalOnMissingBean
21+
@ConditionalOnProperty(prefix = "example.service",value = "enabled",havingValue = "true")
22+
ExampleService exampleService (){
23+
return new ExampleService(properties.getPrefix(),properties.getSuffix());
24+
}
25+
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example.autocinfigure;
2+
3+
public class ExampleService {
4+
5+
private String prefix;
6+
private String suffix;
7+
8+
public ExampleService(String prefix, String suffix) {
9+
this.prefix = prefix;
10+
this.suffix = suffix;
11+
}
12+
public String wrap(String word) {
13+
return prefix + word + suffix;
14+
}
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.example.autocinfigure;
2+
import org.springframework.boot.context.properties.ConfigurationProperties;
3+
@ConfigurationProperties("example.service")
4+
public class ExampleServiceProperties {
5+
private String prefix;
6+
private String suffix;
7+
8+
public String getPrefix() {
9+
return prefix;
10+
}
11+
12+
public void setPrefix(String prefix) {
13+
this.prefix = prefix;
14+
}
15+
16+
public String getSuffix() {
17+
return suffix;
18+
}
19+
20+
public void setSuffix(String suffix) {
21+
this.suffix = suffix;
22+
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.example.autocinfigure.ExampleAutoConfigure

0 commit comments

Comments
 (0)