提交 4e60b372 编写于 作者: 武汉红喜's avatar 武汉红喜

whatsmars-boot-sample-bean

上级 dfed8c50
......@@ -23,6 +23,7 @@
<module>whatsmars-boot-sample-mongodb</module>
<module>whatsmars-boot-sample-redis</module>
<module>whatsmars-boot-sample-mybatis</module>
<module>whatsmars-boot-sample-bean</module>
</modules>
<dependencies>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>whatsmars-spring-boot-samples</artifactId>
<groupId>org.hongxi</groupId>
<version>Rocket.S8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>whatsmars-boot-sample-bean</artifactId>
<name>${project.artifactId}</name>
<packaging>jar</packaging>
<description>Spring Boot Bean Sample</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package org.hongxi.whatsmars.boot.sample.bean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
/**
* Created by shenhongxi on 2020/6/8.
*/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public DemoBean demoBean() {
return new DemoBean();
}
@Bean
public DemoBeanPostProcessor demoBeanPostProcessor() {
return new DemoBeanPostProcessor();
}
}
package org.hongxi.whatsmars.boot.sample.bean;
import org.springframework.beans.factory.InitializingBean;
/**
* Created by shenhongxi on 2020/6/10.
*/
public class DemoBean implements InitializingBean {
public DemoBean() {
System.out.println("new DemoBean");
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("afterPropertiesSet");
}
}
package org.hongxi.whatsmars.boot.sample.bean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
/**
* Created by shenhongxi on 2020/6/10.
*/
public class DemoBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (beanName.equals("demoBean")) {
System.out.println("postProcessBeforeInitialization");
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (beanName.equals("demoBean")) {
System.out.println("postProcessAfterInitialization");
}
return bean;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册