forked from wuyouzhuguli/SpringAll
-
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
0e24aae
commit f620991
Showing
15 changed files
with
240 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.1.0.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>com.example</groupId> | ||
<artifactId>autoconfig</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>demo</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
44.Spring-Boot-Autoconfiguration/src/main/java/com/example/demo/DemoApplication.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,13 @@ | ||
package com.example.demo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class DemoApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DemoApplication.class, args); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...ng-Boot-Autoconfiguration/src/main/java/com/example/demo/annotation/EnableHelloWorld.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,17 @@ | ||
package com.example.demo.annotation; | ||
|
||
import com.example.demo.configuration.HelloWorldConfiguration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author MrBird | ||
*/ | ||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
// @Import(HelloWorldImportSelector.class) | ||
@Import(HelloWorldConfiguration.class) | ||
public @interface EnableHelloWorld { | ||
} |
14 changes: 14 additions & 0 deletions
14
...g-Boot-Autoconfiguration/src/main/java/com/example/demo/annotation/FirstLevelService.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,14 @@ | ||
package com.example.demo.annotation; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Service | ||
public @interface FirstLevelService { | ||
String value() default ""; | ||
} |
11 changes: 11 additions & 0 deletions
11
...-Boot-Autoconfiguration/src/main/java/com/example/demo/annotation/SecondLevelService.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,11 @@ | ||
package com.example.demo.annotation; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@FirstLevelService | ||
public @interface SecondLevelService { | ||
String value() default ""; | ||
} |
22 changes: 22 additions & 0 deletions
22
...figuration/src/main/java/com/example/demo/bootstrap/EnableAutoConfigurationBootstrap.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,22 @@ | ||
package com.example.demo.bootstrap; | ||
|
||
import org.springframework.boot.WebApplicationType; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
/** | ||
* @author MrBird | ||
*/ | ||
@EnableAutoConfiguration | ||
public class EnableAutoConfigurationBootstrap { | ||
|
||
public static void main(String[] args) { | ||
ConfigurableApplicationContext context = new SpringApplicationBuilder(EnableAutoConfigurationBootstrap.class) | ||
.web(WebApplicationType.NONE) | ||
.run(args); | ||
String hello = context.getBean("hello", String.class); | ||
System.out.println("hello Bean: " + hello); | ||
context.close(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ing-Boot-Autoconfiguration/src/main/java/com/example/demo/bootstrap/ServiceBootstrap.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,23 @@ | ||
package com.example.demo.bootstrap; | ||
|
||
import com.example.demo.service.TestService; | ||
import org.springframework.boot.WebApplicationType; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.annotation.ComponentScan; | ||
|
||
/** | ||
* @author MrBird | ||
*/ | ||
@ComponentScan("com.example.demo.service") | ||
public class ServiceBootstrap { | ||
|
||
public static void main(String[] args) { | ||
ConfigurableApplicationContext context = new SpringApplicationBuilder(ServiceBootstrap.class) | ||
.web(WebApplicationType.NONE) | ||
.run(args); | ||
TestService testService = context.getBean("testService", TestService.class); | ||
System.out.println("TestService Bean: " + testService); | ||
context.close(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...g-Boot-Autoconfiguration/src/main/java/com/example/demo/bootstrap/TestEnableBootstap.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,21 @@ | ||
package com.example.demo.bootstrap; | ||
|
||
import com.example.demo.annotation.EnableHelloWorld; | ||
import org.springframework.boot.WebApplicationType; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
/** | ||
* @author MrBird | ||
*/ | ||
@EnableHelloWorld | ||
public class TestEnableBootstap { | ||
public static void main(String[] args) { | ||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestEnableBootstap.class) | ||
.web(WebApplicationType.NONE) | ||
.run(args); | ||
String hello = context.getBean("hello", String.class); | ||
System.out.println("hello Bean: " + hello); | ||
context.close(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...nfiguration/src/main/java/com/example/demo/configuration/HelloWorldAutoConfiguration.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,14 @@ | ||
package com.example.demo.configuration; | ||
|
||
import com.example.demo.annotation.EnableHelloWorld; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @author MrBird | ||
*/ | ||
@Configuration | ||
@EnableHelloWorld | ||
@ConditionalOnProperty(name = "helloworld", havingValue = "true") | ||
public class HelloWorldAutoConfiguration { | ||
} |
16 changes: 16 additions & 0 deletions
16
...toconfiguration/src/main/java/com/example/demo/configuration/HelloWorldConfiguration.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,16 @@ | ||
package com.example.demo.configuration; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @author MrBird | ||
*/ | ||
@Configuration | ||
public class HelloWorldConfiguration { | ||
|
||
@Bean | ||
public String hello() { | ||
return "hello world"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...t-Autoconfiguration/src/main/java/com/example/demo/selector/HelloWorldImportSelector.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,15 @@ | ||
package com.example.demo.selector; | ||
|
||
import com.example.demo.configuration.HelloWorldConfiguration; | ||
import org.springframework.context.annotation.ImportSelector; | ||
import org.springframework.core.type.AnnotationMetadata; | ||
|
||
/** | ||
* @author MrBird | ||
*/ | ||
public class HelloWorldImportSelector implements ImportSelector { | ||
@Override | ||
public String[] selectImports(AnnotationMetadata importingClassMetadata) { | ||
return new String[]{HelloWorldConfiguration.class.getName()}; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
44.Spring-Boot-Autoconfiguration/src/main/java/com/example/demo/service/TestService.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,11 @@ | ||
package com.example.demo.service; | ||
|
||
import com.example.demo.annotation.FirstLevelService; | ||
import com.example.demo.annotation.SecondLevelService; | ||
|
||
/** | ||
* @author MrBird | ||
*/ | ||
@SecondLevelService | ||
public class TestService { | ||
} |
3 changes: 3 additions & 0 deletions
3
44.Spring-Boot-Autoconfiguration/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,3 @@ | ||
# Auto Configure | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
com.example.demo.configuration.HelloWorldAutoConfiguration |
1 change: 1 addition & 0 deletions
1
44.Spring-Boot-Autoconfiguration/src/main/resources/application.properties
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 @@ | ||
helloworld=true |
16 changes: 16 additions & 0 deletions
16
44.Spring-Boot-Autoconfiguration/src/test/java/com/example/demo/DemoApplicationTests.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,16 @@ | ||
package com.example.demo; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class DemoApplicationTests { | ||
|
||
@Test | ||
public void contextLoads() { | ||
} | ||
|
||
} |