Skip to content

Commit 0802daa

Browse files
author
chenpiqian
committed
00
1 parent 4de3a91 commit 0802daa

15 files changed

Lines changed: 185 additions & 77 deletions

File tree

project/spring-source/spring-demo/build.gradle

Lines changed: 0 additions & 17 deletions
This file was deleted.

project/spring-source/spring-demo/src/main/java/com/imooc/A_01.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

project/spring-source/spring-demo/src/main/java/com/imooc/a_service/WelcomeService.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

project/spring-source/spring-demo/src/main/java/com/imooc/a_service/WelcomeServiceImpl.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

project/spring-source/spring-demo/src/main/resources/spring-config.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

project/spring-source/spring-demo1/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@
1919
</properties>
2020

2121
<dependencies>
22+
2223
<dependency>
2324
<groupId>org.springframework.boot</groupId>
2425
<artifactId>spring-boot-starter-web</artifactId>
2526
</dependency>
2627

28+
<dependency>
29+
<groupId>org.projectlombok</groupId>
30+
<artifactId>lombok</artifactId>
31+
<version>1.18.10</version>
32+
</dependency>
33+
2734
<dependency>
2835
<groupId>org.springframework.boot</groupId>
2936
<artifactId>spring-boot-starter-test</artifactId>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.imooc.c_refresh;
2+
3+
import org.springframework.beans.BeansException;
4+
import org.springframework.beans.factory.BeanNameAware;
5+
import org.springframework.context.ApplicationContext;
6+
import org.springframework.context.ApplicationContextAware;
7+
import org.springframework.stereotype.Controller;
8+
9+
10+
@Controller
11+
public class C1_Aware implements ApplicationContextAware, BeanNameAware {
12+
13+
/**
14+
* Aware是获取本bean(c1_Aware)的容器,
15+
* 例如通过BeanNameAware获取bean在容器中的名称
16+
* ApplicationContextAware获取bean对应的applicationContext
17+
*
18+
* 正常情况下,bean不会感知到容器的存在,bean与容器是解耦的
19+
* 使用Aware,bean能获取容器信息,导致bean与容器耦合了
20+
*/
21+
private String myName;
22+
private ApplicationContext myContainer;
23+
24+
public void testAware(){
25+
System.out.println("#####myName###"+myName);
26+
String[] beanDefinitionNames = myContainer.getBeanDefinitionNames();
27+
for (String bean : beanDefinitionNames) {
28+
System.out.println("#####getBeanDefinitionNames###"+bean);
29+
}
30+
}
31+
32+
@Override
33+
public void setBeanName(String name) {
34+
this.myName = name;
35+
}
36+
37+
@Override
38+
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
39+
this.myContainer = applicationContext;
40+
}
41+
42+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.imooc.c_refresh;
2+
3+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
@ComponentScan("com.imooc.c_refresh")
9+
public class C2_AwareLearn {
10+
11+
public static void main(String[] args) {
12+
AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(A1_PostProcessor.class);
13+
C1_Aware c1_aware = (C1_Aware)app.getBean("c1_Aware");
14+
c1_aware.testAware();
15+
}
16+
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.imooc.d_refresh_listener;
2+
3+
import org.springframework.core.ResolvableType;
4+
5+
import java.util.HashMap;
6+
import java.util.List;
7+
8+
public class B_ResolvebleDemo {
9+
10+
private HashMap<String, List<Integer>> customizedMap;
11+
12+
/**
13+
* ResolvableType可以获取Class、Filed、Method的泛型
14+
*/
15+
public static void main(String[] args) throws NoSuchFieldException {
16+
ResolvableType resolvableType = ResolvableType.forField(B_ResolvebleDemo.class.getDeclaredField("customizedMap"));
17+
System.out.println("######resolvableType.getGeneric(0).resolve() "+resolvableType.getGeneric(0).resolve());
18+
System.out.println("######resolvableType.getGeneric(1).resolve() "+resolvableType.getGeneric(1).resolve());
19+
System.out.println("######resolvableType.getGeneric(1) "+resolvableType.getGeneric(1));
20+
System.out.println("######resolvableType.getSuperType() "+resolvableType.getSuperType());
21+
System.out.println("######resolvableType.asMap() "+resolvableType.asMap());
22+
System.out.println("######resolvableType.resolveGeneric(1,0) "+resolvableType.resolveGeneric(1,0));
23+
}
24+
25+
/**
26+
* com.imooc.b_ioc_learn.D_AbstractApplicationContext#refresh() 是重点
27+
*/
28+
29+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.imooc.d_refresh_listener.a_listener;
2+
3+
/**
4+
* @author chenpiqian
5+
* @date: 2020-07-17
6+
*/
7+
public class DoubleClickEventListener implements EventListener {
8+
@Override
9+
public void processEvent(Event event) {
10+
if ("doubleClick".equals(event.getType())){
11+
System.out.println("#####双击被触发了####");
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)