File tree Expand file tree Collapse file tree 4 files changed +46
-12
lines changed
java/com/bruis/learnsb/condi
test/java/com/bruis/learnsb Expand file tree Collapse file tree 4 files changed +46
-12
lines changed Original file line number Diff line number Diff line change @@ -24,16 +24,17 @@ Java流行框架源码分析,学习以及总结。
2424
2525框架包括:
2626
27- 1 . Spring源码【更新中】
28- 2 . SpringBoot源码【更新中】
29- 3 . SpringAOP源码【更新中】
30- 4 . SpringSecurity源码【更新中】
31- 5 . SpringSecurity OAuth2源码【更新中】
32- 6 . JDK源码【更新中】
33- 7 . Netty源码(待)
34- 8 . MyBatis(待)
35- 9 . Dubbo源码【更新中】
36- 10 . SpringCloud(待)
27+
28+ - [x] Spring源码
29+ - [x] SpringBoot源码
30+ - [x] SpringAOP源码
31+ - [x] SpringSecurity源码
32+ - [x] SpringSecurity OAuth2源码
33+ - [x] JDK源码
34+ - [ ] Netty源码
35+ - [ ] MyBatis源码
36+ - [x] Dubbo源码
37+ - [ ] SpringCloud源码
3738
3839> 为什么要分析、学习源码?
3940
Original file line number Diff line number Diff line change 1+ package com .bruis .learnsb .condi ;
2+
3+ import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
4+ import org .springframework .stereotype .Component ;
5+
6+ /**
7+ * @author LuoHaiYang
8+ */
9+ @ Component
10+ // 当存在com.bruis.condition这个配置时才注入ConditionTest这个bean
11+ @ ConditionalOnProperty ("com.bruis.condition" )
12+ public class ConditionTest {
13+ }
Original file line number Diff line number Diff line change @@ -2,4 +2,5 @@ server.port=8802
22context.initializer.classes =com.bruis.learnsb.initializer.SecondInitializer
33context.listener.classes =com.bruis.learnsb.listener.ThirdListener,com.bruis.learnsb.listener.FourthListener
44
5- bruis.github.url =properties-https://github.com/coderbruis/JavaSourceLearning
5+ bruis.github.url =properties-https://github.com/coderbruis/JavaSourceLearning
6+ com.bruis.condition =ConditionTest
Original file line number Diff line number Diff line change 11package com .bruis .learnsb ;
22
3+ import com .bruis .learnsb .condi .ConditionTest ;
34import org .junit .Test ;
45import org .junit .runner .RunWith ;
6+ import org .springframework .beans .BeansException ;
57import org .springframework .boot .test .context .SpringBootTest ;
8+ import org .springframework .context .ApplicationContext ;
9+ import org .springframework .context .ApplicationContextAware ;
610import org .springframework .test .context .junit4 .SpringRunner ;
711
812@ RunWith (SpringRunner .class )
913@ SpringBootTest
10- public class ApplicationTests {
14+ public class ApplicationTests implements ApplicationContextAware {
15+
16+ private ApplicationContext applicationContext ;
17+
18+ @ Override
19+ public void setApplicationContext (ApplicationContext applicationContext ) throws BeansException {
20+ this .applicationContext = applicationContext ;
21+ }
1122
1223 @ Test
1324 public void contextLoads () {
1425 }
1526
27+ /**
28+ * 测试当前SpringIOC容器中是否存在ConditionTest这个bean
29+ */
30+ @ Test
31+ public void testConditionTest () {
32+ System .out .println (applicationContext .getBean (ConditionTest .class ));
33+ }
34+
1635}
You can’t perform that action at this time.
0 commit comments