Skip to content

Commit 72a54b3

Browse files
committedApr 26, 2019
Add episode 24
1 parent ad67a0b commit 72a54b3

File tree

1 file changed

+190
-0
lines changed
  • 2019.04.26 「小马哥技术周报」- 第二十四期《Spring Core 面试题精选》

1 file changed

+190
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# 2019.04.26 「小马哥技术周报」- 第二十四期《Spring Core 面试题精选》
2+
3+
4+
5+
## 精选
6+
7+
8+
9+
### 为什么要使用 Spring?
10+
11+
###
12+
13+
### 解释一下什么是 IoC?
14+
15+
好莱坞原则
16+
17+
BeanFactory
18+
19+
20+
21+
Spring -> Interface21
22+
23+
BeanFactory
24+
25+
1.0 ~ 2.0 XML 主导
26+
27+
1.2+ ~ 5.2(PRE) 注解
28+
29+
2.0 注解
30+
31+
32+
33+
<bean id="user" class="User" >
34+
35+
36+
37+
<bean class="XXX">
38+
39+
​ <property bean-ref="user" />
40+
41+
</bean>
42+
43+
### Spring 中的 bean 是线程安全的吗?
44+
45+
Bean 对象的本身是否为是不确定的。
46+
47+
48+
49+
<bean id="map" class="java.util.concurrent.ConcurrentHashMap" />
50+
51+
> 获得 Bean 是线程安全
52+
53+
54+
55+
### Spring 常用的注入方式有哪些?
56+
57+
Setter(方法参数)
58+
59+
构造器(参数)
60+
61+
方法注入
62+
63+
```java
64+
// @Autowired 可选
65+
public User user(Money money){
66+
67+
}
68+
```
69+
70+
71+
72+
### Spring 支持几种 bean 的作用域?
73+
74+
```xml
75+
<bean id="map" class="java.util.concurrent.ConcurrentHashMap" scope="prototype" />
76+
```
77+
78+
79+
80+
request -> ServletRequest
81+
82+
83+
84+
Servlet 引擎的线程模型 1 Thread -> 1 ServletRequest
85+
86+
ServletRequest 是线程安全的
87+
88+
89+
90+
HTTP -> Tomcat(NIO) -> Thread -> Request( Bean)
91+
92+
93+
94+
```java
95+
@RestController
96+
public class MyController {
97+
98+
@Autowired
99+
private User user;
100+
101+
@GetMapping("/user/xxx")
102+
public void execute(){
103+
user.getName();
104+
}
105+
}
106+
```
107+
108+
109+
110+
JSP、JSTL、EL
111+
112+
Page - `PageContext`
113+
114+
Request - `ServletRequest`
115+
116+
Session - `HttpSession`
117+
118+
Application - `ServletContext`
119+
120+
121+
122+
### Spring 自动装配(Autowired) bean 有哪些方式?
123+
124+
Type
125+
126+
Name
127+
128+
Constructor
129+
130+
Auto detected
131+
132+
`AUTOWIRE_NO`
133+
134+
`AUTOWIRE_BY_NAME`
135+
136+
`AUTOWIRE_BY_TYPE`
137+
138+
`AUTOWIRE_CONSTRUCTOR`
139+
140+
`AUTOWIRE_AUTODETECT`
141+
142+
143+
144+
### 如何理解 Bean 的生命周期?
145+
146+
147+
148+
AbstractAutowireCapableBeanFactory
149+
150+
- invokeAwareMethods
151+
152+
ApplicationContextAwareProcessor
153+
154+
- ApplicationContextAware
155+
- BeanClassLoaderAware
156+
- ...
157+
158+
BeanPostProcessor
159+
160+
- InstantiationAwareBeanPostProcessor
161+
- SmartInstantiationAwareBeanPostProcessor
162+
163+
- postProcessBeforeInitialization()
164+
- postProcessAfterInitialization()
165+
166+
InitializaingBean
167+
168+
- afterPropertiesSet()
169+
170+
DisposableBean
171+
172+
- destroy()
173+
174+
175+
176+
### Spring 事务实现方式有哪些?
177+
178+
179+
180+
### 说一下 Spring 的事务隔离?
181+
182+
183+
184+
### @Autowired 的作用是什么?
185+
186+
@Autowired 用于依赖注入,Spring 官方不推荐使用,推荐使用构造器注入。不能修饰 static 字段
187+
188+
189+
190+
QQ 3群:982215002

0 commit comments

Comments
 (0)