GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — :sparkles: Introducing new features.Spring lifecycle · sustbeckham/Java-Interview@ebffa51

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • MD/spring
    • spring-bean-lifecycle.md
  • src/main/java/com/crossoverjie/spring/processor
    • SpringLifeCycleProcessor.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎MD/spring/spring-bean-lifecycle.md‎

Copy file name to clipboardExpand all lines: MD/spring/spring-bean-lifecycle.md
+16-1Lines changed: 16 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,22 @@ public class SpringLifeCycleAware implements ApplicationContextAware {
115115

116116
这样在 `springLifeCycleAware` 这个 bean 初始化会就会调用 `setApplicationContext` 方法,并可以获得 `applicationContext` 对象。
117117

118-
### BeanPostProcessor 后处理器
118+
### BeanPostProcessor 增强处理器
119119

120120
实现 BeanPostProcessor 接口,Spring 中所有 bean 在做初始化时都会调用该接口中的两个方法,可以用于对一些特殊的 bean 进行处理:
121121

122122
```java
123123
@Component
124124
public class SpringLifeCycleProcessor implements BeanPostProcessor {
125125
private final static Logger LOGGER = LoggerFactory.getLogger(SpringLifeCycleProcessor.class);
126+
127+
/**
128+
* 预初始化 初始化之前调用
129+
* @param bean
130+
* @param beanName
131+
* @return
132+
* @throws BeansException
133+
*/
126134
@Override
127135
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
128136
if ("annotationBean".equals(beanName)){
@@ -131,6 +139,13 @@ public class SpringLifeCycleProcessor implements BeanPostProcessor {
131139
return bean;
132140
}
133141

142+
/**
143+
* 后初始化 bean 初始化完成调用
144+
* @param bean
145+
* @param beanName
146+
* @return
147+
* @throws BeansException
148+
*/
134149
@Override
135150
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
136151
if ("annotationBean".equals(beanName)){
Collapse file

‎src/main/java/com/crossoverjie/spring/processor/SpringLifeCycleProcessor.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/crossoverjie/spring/processor/SpringLifeCycleProcessor.java
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
@Component
1818
public class SpringLifeCycleProcessor implements BeanPostProcessor {
1919
private final static Logger LOGGER = LoggerFactory.getLogger(SpringLifeCycleProcessor.class);
20+
21+
/**
22+
* 预初始化 初始化之前调用
23+
* @param bean
24+
* @param beanName
25+
* @return
26+
* @throws BeansException
27+
*/
2028
@Override
2129
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
2230
if ("annotationBean".equals(beanName)){
@@ -25,6 +33,13 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
2533
return bean;
2634
}
2735

36+
/**
37+
* 后初始化 bean 初始化完成调用
38+
* @param bean
39+
* @param beanName
40+
* @return
41+
* @throws BeansException
42+
*/
2843
@Override
2944
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
3045
if ("annotationBean".equals(beanName)){

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.