forked from fafeidou/fast-cloud-nacos
-
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
qinfuxiang
committed
Nov 24, 2021
1 parent
643fd72
commit 9d94c37
Showing
1 changed file
with
28 additions
and
7 deletions.
There are no files selected for viewing
35 changes: 28 additions & 7 deletions
35
...es/auto-configure/src/main/java/fast/boot/autoconfigure/autowired/AutowiredBootstrap.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 |
---|---|---|
@@ -1,14 +1,35 @@ | ||
package fast.boot.autoconfigure.autowired; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.stereotype.Component; | ||
|
||
@SpringBootApplication | ||
@ComponentScan | ||
@Configuration | ||
public class AutowiredBootstrap { | ||
public static void main(String[] args) { | ||
ConfigurableApplicationContext context = SpringApplication.run(AutowiredBootstrap.class, args); | ||
A a = context.getBean(A.class); | ||
System.out.println(a); | ||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AutowiredBootstrap.class); | ||
A a = applicationContext.getBean(A.class); | ||
a.test(); | ||
applicationContext.registerShutdownHook(); | ||
} | ||
|
||
@Component | ||
public class A { | ||
|
||
@Autowired | ||
private B b; | ||
|
||
public void test() { | ||
System.out.println(b); | ||
} | ||
|
||
} | ||
|
||
@Component | ||
public class B { | ||
} | ||
|
||
} |