Skip to content

Commit 49a8cf0

Browse files
committed
code examples for the article 38 the lifecycle of spring beans
1 parent c657c7c commit 49a8cf0

24 files changed

Lines changed: 667 additions & 0 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.gradle
2+
/build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
5+
### STS ###
6+
.apt_generated
7+
.classpath
8+
.factorypath
9+
.project
10+
.settings
11+
.springBeans
12+
.sts4-cache
13+
14+
### IntelliJ IDEA ###
15+
.idea
16+
*.iws
17+
*.iml
18+
*.ipr
19+
/out/
20+
21+
### NetBeans ###
22+
/nbproject/private/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
plugins {
2+
id 'org.springframework.boot' version '2.3.2.RELEASE'
3+
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
4+
id 'java'
5+
}
6+
7+
group = 'io.reflectoring'
8+
version = '0.0.1-SNAPSHOT'
9+
sourceCompatibility = '11'
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
implementation 'org.springframework.boot:spring-boot-starter'
17+
implementation 'org.springframework.boot:spring-boot-starter-quartz'
18+
implementation 'org.springframework.boot:spring-boot-starter-jersey'
19+
testImplementation('org.springframework.boot:spring-boot-starter-test') {
20+
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
21+
}
22+
}
23+
24+
test {
25+
useJUnitPlatform()
26+
}
53.4 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Tue Feb 06 12:27:20 CET 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

spring-boot/bean-lifecycle/gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring-boot/bean-lifecycle/gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'beanlifecycle'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.reflectoring.beanlifecycle;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class BeanLifecycleApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(BeanLifecycleApplication.class, args);
11+
}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.reflectoring.beanlifecycle;
2+
3+
import org.springframework.beans.BeansException;
4+
import org.springframework.beans.factory.config.BeanPostProcessor;
5+
6+
public class MyBeanPostProcessor implements BeanPostProcessor {
7+
8+
@Override
9+
public Object postProcessBeforeInitialization(Object bean, String beanName)
10+
throws BeansException {
11+
if (bean instanceof MySpringBean) {
12+
System.out.println("--- postProcessBeforeInitialization executed ---");
13+
}
14+
return bean;
15+
}
16+
17+
@Override
18+
public Object postProcessAfterInitialization(Object bean, String beanName)
19+
throws BeansException {
20+
if (bean instanceof MySpringBean) {
21+
System.out.println("--- postProcessAfterInitialization executed ---");
22+
}
23+
return bean;
24+
}
25+
26+
}

0 commit comments

Comments
 (0)