【转】比较init-method,afterPropertiesSet和BeanPostProcessor
一、简单介绍
1、init-method方法,初始化bean的时候执行,可以针对某个具体的bean进行配置。init-method需要在applicationContext.xml配置文档中bean的定义里头写明。例如:<bean id="TestBean" class="nju.software.xkxt.util.TestBean" init-method="init"></bean>
- package nju.software.xkxt.util;
- import org.springframework.beans.BeansException;
- import org.springframework.beans.factory.config.BeanPostProcessor;
- /**
- * 定义Bean初始化前后的动作
- *
- * @author typ
- *
- */
- public class PostProcessor implements BeanPostProcessor {
- @Override
- public Object postProcessBeforeInitialization(Object bean, String beanName)
- throws BeansException {
- System.out.println("------------------------------");
- System.out.println("对象" + beanName + "开始实例化");
- return bean;
- }
- @Override
- public Object postProcessAfterInitialization(Object bean, String beanName)
- throws BeansException {
- System.out.println("对象" + beanName + "实例化完成");
- System.out.println("------------------------------");
- return bean;
- }
- }
- package nju.software.xkxt.util;
- import org.springframework.beans.factory.InitializingBean;
- /**
- * 用做测试Bean,观察该Bean初始化过程中上面4个方法执行的先后顺序和内容
- *
- * @author typ
- *
- */
- public class TestBean implements InitializingBean {
- String name;
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void init() {
- System.out.println("init-method is called");
- System.out.println("******************************");
- }
- @Override
- public void afterPropertiesSet() throws Exception {
- System.out.println("******************************");
- System.out.println("afterPropertiesSet is called");
- System.out.println("******************************");
- }
- }
------------------------------
【转】比较init-method,afterPropertiesSet和BeanPostProcessor的更多相关文章
- SSH项目练习的时候报错:[applicationContext.xml]: Invocation of init method failed;
这里是控制台的报错信息:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' ...
- MyBatis笔记----报错:Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/ij34/mybatis/applicationContext.xml]: Invocation of init method failed; nested exception is org.sp
四月 05, 2017 4:51:02 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRef ...
- 简单比较init-method,afterPropertiesSet和BeanPostProcessor
一.简单介绍 1.init-method方法,初始化bean的时候执行,可以针对某个具体的bean进行配置.init-method需要在applicationContext.xml配置文档中bean的 ...
- org.springframework.beans.factory.BeanCreationException,Invocation of init method failed,Context initialization failed
G:\javaanzhuang\apache-tomcat-\bin\catalina.bat run [-- ::,] Artifact ssm_qingmu02_web:war exploded: ...
- Invocation of init method failed; nested exception is java.text.ParseException: '?' can only be specfied for Day-of-Month or Day-of-Week.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cronTrigger' ...
- Spring报错: org.springframework.beans.factory.support.BeanDefinitionValidationException: Couldn't find an init method named 'init' on bean with name 'car'(待解答)
在Spring工程里,有一个Car类的bean,Main.java主程序,MyBeanPostProcessor.java是Bean后置处理器. 文件目录结构如下: Car.java package ...
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [bean.xml]: Invocation of init method failed; nested exception is
在复制xml文件进行修改的时候,我经常将不小心对原文件进行修改,而导致创建bean出错.报错如下所示: Exception sending context initialized event to l ...
- Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method fail
SpringBoot 单元测试报错 @RunWith(SpringRunner.class) @SpringBootTest public class ProductCategoryRepositor ...
- Error creating bean with name 'userRepository': Invocation of init method failed;
2019-11-25 19:43:49.482 INFO 6528 --- [ main] c.g.c.y.core.impl.AbstractController : Controller has ...
- The init method
The init method is a special method that gets invoked when an object is instantiated. Its full name ...
随机推荐
- GPU下train 模型出现nan
When training on GPU, the error "Model diverged with loss = NaN" is often caused by a sotm ...
- tensorflow函数(2)
并行计算能让代价大的算法计算加速执行,TensorFlow也在实现上对复杂操作进行了有效的改进.大部分核相关的操作都是设备相关的实现,比如GPU.下面是一些重要的操作/核: 操作组 操作 Maths ...
- The last access date is not changed even after reading the file on Windows 7
https://superuser.com/questions/251263/the-last-access-date-is-not-changed-even-after-reading-the-fi ...
- Spring Cloud微服务视频教程-百度云
Spring Cloud微服务视频教程-百度云 链接:https://pan.baidu.com/s/1mp8SkxNw7EfoTDtDKQMpIA 提取码: 关注公众号[GitHubCN]回复521 ...
- vue报错 ModuleBuildError: Module build failed: Error: `sass-loader` requires `node-sass` >=4. Please install a compatible version.
解决方法: 输入命令:cnpm install node-sass@latest
- 【PAT】1052 Linked List Sorting (25)(25 分)
1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...
- Jupyter notebook安装与使用
Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言. 安装 安装python 3 pip安装 pip3 install - ...
- hadoop2.6.4的HA集群搭建超详细步骤
hadoop2.0已经发布了稳定版本了,增加了很多特性,比如HDFS HA.YARN等.最新的hadoop-2.6.4又增加了YARN HA 注意:apache提供的hadoop-2.6.4的安装包是 ...
- 如何对手机使用adb
因为要配合前端做测试,所以我需要在本机中安装adb驱动,以便可以连接手机进行各种操作. 好吧...装adb驱动这块当时我没有把流程给做记录...郁闷,下次再安装的时候再谷歌吧. 使用的简单脚本就是 有 ...
- jQuery的类数组对象结构(转)
原文:http://www.imooc.com/code/3248 为什么是类数组对象呢? 很多人迷惑的jQuery为什么能像数组一样操作,通过对象get方法或者直接通过下标0索引就能转成DOM对象. ...