- 浏览: 837136 次
文章分类
- 全部博客 (365)
- java (124)
- spring mvc (21)
- spring (22)
- struts2 (6)
- jquery (27)
- javascript (24)
- mybatis/ibatis (8)
- hibernate (7)
- compass (11)
- lucene (26)
- flex (0)
- actionscript (0)
- webservice (8)
- rabbitMQ/Socket (15)
- jsp/freemaker (5)
- 数据库 (27)
- 应用服务器 (21)
- Hadoop (1)
- PowerDesigner (3)
- EJB (0)
- JPA (0)
- PHP (2)
- C# (0)
- .NET (0)
- html (2)
- xml (5)
- android (7)
- flume (1)
- zookeeper (0)
- 证书加密 (2)
- maven (1)
- redis (2)
- cas (11)
最新评论
-
zuxianghuang:
通过pom上传报错 Artifact upload faile ...
nexus上传了jar包.通过maven引用当前jar,不能取得jar的依赖 -
流年末年:
百度网盘的挂了吧???
SSO单点登录系列3:cas-server端配置认证方式实践(数据源+自定义java类认证) -
953434367:
UfgovDBUtil 是什么类
Java发HTTP POST请求(内容为xml格式) -
smilease:
帮大忙了,非常感谢
freemaker自动生成源代码 -
syd505:
十分感谢作者无私的分享,仔细阅读后很多地方得以解惑。
Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
Life类
- package com.open.bean;
- import org.springframework.beans.BeansException;
- import org.springframework.beans.factory.BeanFactory;
- import org.springframework.beans.factory.BeanFactoryAware;
- import org.springframework.beans.factory.BeanNameAware;
- import org.springframework.beans.factory.DisposableBean;
- import org.springframework.beans.factory.InitializingBean;
- public class Life implements BeanFactoryAware, BeanNameAware,
- InitializingBean, DisposableBean {
- private String msg;
- public Life() {
- System.out.println("msg="+msg);
- System.out.println("构造函数");
- }
- public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
- System.out.println("setBeanFactory");
- }
- public void setBeanName(String name) {
- System.out.println("setBeanName");
- }
- public void init() {
- System.out.println("初始化");
- }
- public Object postProcessBeforeInitialization(Object bean, String beanName)
- throws BeansException {
- System.out.println("postProcessBeforeInitialization");
- return null;
- }
- public Object postProcessAfterInitialization(Object bean, String beanName)
- throws BeansException {
- System.out.println("postProcessAfterInitialization");
- return null;
- }
- public void afterPropertiesSet() throws Exception {
- System.out.println("afterPropertiesSet");
- }
- public void destroy() throws Exception {
- System.out.println("destroy");
- }
- public String getMsg() {
- return msg;
- }
- public void setMsg(String msg) {
- this.msg = msg;
- }
- }
package com.open.bean; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; public class Life implements BeanFactoryAware, BeanNameAware, InitializingBean, DisposableBean { private String msg; public Life() { System.out.println("msg="+msg); System.out.println("构造函数"); } public void setBeanFactory(BeanFactory beanFactory) throws BeansException { System.out.println("setBeanFactory"); } public void setBeanName(String name) { System.out.println("setBeanName"); } public void init() { System.out.println("初始化"); } public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { System.out.println("postProcessBeforeInitialization"); return null; } public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { System.out.println("postProcessAfterInitialization"); return null; } public void afterPropertiesSet() throws Exception { System.out.println("afterPropertiesSet"); } public void destroy() throws Exception { System.out.println("destroy"); } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } }
BeanPostProcessorImp类
- package com.open.bean;
- import org.springframework.beans.BeansException;
- import org.springframework.beans.factory.config.BeanPostProcessor;
- public class BeanPostProcessorImp implements BeanPostProcessor {
- public Object postProcessBeforeInitialization(Object bean, String beanName)
- throws BeansException {
- System.out.println("postProcessBeforeInitialization");
- return bean;
- }
- public Object postProcessAfterInitialization(Object bean, String beanName)
- throws BeansException {
- System.out.println("postProcessAfterInitialization");
- return bean;
- }
- }
package com.open.bean; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; public class BeanPostProcessorImp implements BeanPostProcessor { public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { System.out.println("postProcessBeforeInitialization"); return bean; } public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { System.out.println("postProcessAfterInitialization"); return bean; } }
BeanCounter类
- package com.open.bean;
- import org.springframework.beans.BeansException;
- import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
- import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
- public class BeanCounter implements BeanFactoryPostProcessor {
- public void postProcessBeanFactory(
- ConfigurableListableBeanFactory beanFactory) throws BeansException {
- System.out.println("类的数量="+beanFactory.getBeanDefinitionCount());
- }
- }
package com.open.bean; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; public class BeanCounter implements BeanFactoryPostProcessor { public void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory) throws BeansException { System.out.println("类的数量="+beanFactory.getBeanDefinitionCount()); } }
bean.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
- "http://www.springframework.org/dtd/spring-beans.dtd">
- <beans>
- <bean id="life" name="life_name" class="com.open.bean.Life"
- init-method="init">
- <property name="msg" value="lifexxxx"/>
- </bean>
- <bean id="processor" class="com.open.bean.BeanPostProcessorImp"/>
- <bean id="counter" class="com.open.bean.BeanCounter"/>
- </beans>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="life" name="life_name" class="com.open.bean.Life" init-method="init"> <property name="msg" value="lifexxxx"/> </bean> <bean id="processor" class="com.open.bean.BeanPostProcessorImp"/> <bean id="counter" class="com.open.bean.BeanCounter"/> </beans>
测试类
- package com.open.bean;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class Test {
- public static void main(String[] args) {
- ClassPathXmlApplicationContext cx=
- new ClassPathXmlApplicationContext("bean.xml");
- Life life=(Life)cx.getBean("life");
- }
- }
package com.open.bean; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { public static void main(String[] args) { ClassPathXmlApplicationContext cx= new ClassPathXmlApplicationContext("bean.xml"); Life life=(Life)cx.getBean("life"); } }
输出结果
类的数量=3
msg=null
构造函数
setBeanName
setBeanFactory
postProcessBeforeInitialization
afterPropertiesSet
初始化
postProcessAfterInitialization
发表评论
-
Spring事务的传播行为和隔离级别
2015-01-23 09:15 568Spring事务的传播行为和隔离级别[transaction ... -
Spring3.2.8+Mybatis3.2.6+Maven 整合配置
2015-01-06 14:01 1407 -
采用AOP+log4j记录项目日志
2014-10-28 16:39 460关于AOP,我之前对AOP ... -
Spring Security3.1实践
2014-05-07 14:45 977说明下: 本篇博客时间久远,数 ... -
SpringMVC3.0+MyIbatis3.0(分页示例)
2013-10-30 17:24 2170参考资料 1 ibatis2.x与mybatis ... -
网上的一篇spring security详解教程,觉得不错,转过来了
2013-07-30 22:16 1305先来谈一谈Acegi的基础知识,Acegi的架构比较复杂,但 ... -
Spring Security3配置使用
2013-07-30 16:48 3444使用Spring Security3的 ... -
SSH项目中加入spring security(二)--加入自定义数据表
2013-07-30 13:32 994上一篇中基本的spring security已经加入到项 ... -
SSH项目中加入spring security(一)
2013-07-30 13:30 1518很久没有写过博客了,最近项目中 ... -
Spring定时任务的几种实现
2013-01-22 18:27 826近日项目开发中需要执行一些定时任务,比如需要在 ... -
spring security权限管理手册升级至spring security-3.1.3
2012-12-08 12:57 1934企业应用 费了半天劲,终于把原来基于spri ... -
在Spring、Hibernate中使用Ehcache缓存
2012-11-02 21:49 884前一篇http://www.blogjava.n ... -
不重复配置——利用Spring通用化配置
2012-10-17 09:40 952还记得 如下这种配置吗: 1、struts2作用域 ... -
Ehcache 整合Spring 使用页面、对象缓存
2012-10-16 09:44 755Ehcache在很多项目中都出现过,用法也比较简单。一般的 ... -
Spring AOP 中的通知
2012-09-16 13:32 11932010-08-29 16:54:18| ... -
Spring Security3十五日研究
2012-09-12 10:22 1899前言 南朝《述 ... -
spring2.5 的 security 权限验证
2012-09-09 08:12 903package com.hd.security.se ... -
Spring MVC和Struts2的区别
2012-09-08 08:59 10041. 机制:spring mvc的入口是servlet,而st ... -
跟我学spring3.0 电子书
2012-08-30 13:13 1160好东西 收藏!学习! -
Spring Bean Scope 有状态的Bean 无状态的Bean
2012-08-30 08:58 2410在Spring的Bean配置中 ...
相关推荐
Spring Bean创建初始化流程
本篇文章主要介绍了Spring 中如何控制2个bean中的初始化顺序,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
3、通过spring的xml bean配置或bean注解指定初始化方法,如下面实例的initMethod方法通过@bean注解指定。 销毁的时候实现的方法 1、通过java提供的@PreDestroy注释; 2、通过实现spring提供的DisposableBean接口,并...
springBean加载过程源码解析文档,附有代码类名和行数
主要介绍了Spring Bean的初始化和销毁,结合实例形式详细分析了Spring Bean的初始化和销毁相关配置、使用方法及操作注意事项,需要的朋友可以参考下
spring的初始化,可以让初学者了解soring的开发过程,让开发轻松进入开发大门。
Spring bean 一般通过配置文件和注解进行加载,如果要实现jar或class...测试示例中是spring boot 的部分代码,动态加载的内容为接口实现类,且初始化时加载本地的实现类,动态加载后改为非程序加载目录中的jar实现类。
初始化后可访问Spring管理的Bean
下面小编就为大家带来一篇浅谈spring容器中bean的初始化。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Spring源码学习六:bean初始化1
本篇将对定义在 XMl 文件中的 bean,从静态的的定义到变成可以使用的对象的过程,即 bean 的加载和获取的过程进行一个整体的了解
主要介绍了Spring Bean初始化及销毁多种实现方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Spring 源码分析(Bean的初始化) 前言 本篇文章是个人第一次看spring源码并总结,同时也参考了下面这篇博客。基本也是按照他的思路来理解的。这也算是第一版个人简易理解。也算是窥见spring的冰山一角,之后也会...
NULL 博文链接:https://bijian1013.iteye.com/blog/2374256
只需要把需要注册进容器的bean声明为@Component即可,spring会自动扫描到这个Bean完成初始化并加载到spring上下文容器。 而当你在项目启动时需要提前做一个业务的初始化工作时,或者你正在开发某个中间件需要完成...
为了便于这些工作的设计,Spring IoC 容器提供了相关的功能,可以让应用定制 Bean 的初始化和销毁过程。 Bean 生命周期 的 init-method 属性或 @Bean 注解的 initMethod 属性),那么将调用该方法。 如果存在与 ...
Spring 延迟实例化
【课程介绍】:Spring启动时读取应用提供的Bean配置信息,在Spring容器中生成对应的Bean配置注册表...从源码证明springbean的实例化过程.mp44.spring的核心getSingleton方法.mp45.springbean的生成与循环依赖.mp46.getB
附件是在Spring Boot项目中使用CommandLineRunner接口来执行一些资源初始化的演示,该文档也详细的介绍了在@Component注解的类中可以注入@Controller,并把获取的数据存放到其他Bean类中的私有静态变量,算是对自己...