【转】比较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 ...
随机推荐
- Java基础92 MySQL插入当前系统时间
1.时间格式 用yyyy表示年份(year). -- y 表示年的最后一位,yy 表示年的最后2位,yyy 表示年的最后3位,yyyy 用4位数表示年用MM表示月份(month).-- mm 用2位 ...
- generator自动生成代码
idea设置generator自动生成代码: http://blog.csdn.net/sunny243788557/article/details/45166397
- KnockoutJs学习笔记(八)
with binding用于创建一个新的绑定环境(binding context),包含with binding的元素的所有子元素都将处于指定的object的环境限定内. 下面是一个简单的使用with ...
- django中注册功能signup的测试例
这个是套路, 有了这些测试用例, 开发就会更有保障, 且每次重写,都好麻烦, 不好cp来得快~~:) from django.test import TestCase from django.urls ...
- Docker 图形化页面管理工具使用
一.Docker图形化工具 docker 图形页面管理工具常用的有三种,DockerUI ,Portainer ,Shipyard .DockerUI 是 Portainer 的前身,这三个工具通过d ...
- Nginx+redis的Asp.net
基于Nginx+redis的Asp.net站点搭建 剧情介绍 在传统的信息系统(比如小规模的ERP\MES系统),往往只是进行简单的应用服务器和数据库服务器的分布式部署,以此来提高应用系统的负载能 ...
- React Hooks新特性学习随笔
React Hooks 是 React 16.8 的新增特性.它可以让你在不编写 class 的情况下使用 state 以及其他的 React 特性. 前言 本篇主要以讲几个常用的api为主. 1.u ...
- mac那些事儿
OS是苹果公司开发的电脑操作系统,MAC是苹果公司开发的笔记本.台式机.IOS是苹果公司开发的移动操作系统,iPhone是苹果公司研发的智能手机系列,搭载IOS操作系统. 一.mac系统快捷键 回到桌 ...
- UOJ.179.线性规划(单纯形)
题目链接 这写得还不错:http://www.cnblogs.com/zzqsblog/p/5457091.html 引入基变量\(x_{i+n}\),将约束\(\sum_{i=1}^m a_{ij} ...
- [HDU5714]拍照
[HDU5714]拍照 题目大意: 河上有\(n(n\le10^4)\)个船只,小明希望把尽可能多的船只都完整地拍到一张照片中. 小明位于河的边上,并且可以在河边的任意位置进行拍照,照相机的视野恰好为 ...