`
不吃鱼的猫
  • 浏览: 25284 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Spring-Bean Management 笔记

阅读更多

BeanFactory vs ApplicationContext
Both of them are Interface
ApplicationContext extends BeanFactory indirectly.
(api for ApplicationContext:http://www.springframework.org/docs/api/org/springframework/context/ApplicationContext.html)

ApplicationContext provide extra functionality such as I18N, send event to the bean which subscribed as listener.
provide common method for loading resource.

Three implementation for AppilcationContext is widely used.
ClassPathXmlApplicationContext
FileSystemXmlApplicationContext
XmlWebApplicationContext(load context information in Web System)

BeanFactory lazy load all beans, it is actually loaded when getBean() is invoked.
ApplicationContext preload all the singleton Bean.

Lift cycle of a Bean in spring. 
1.instantiation
2.configurate all the propeties defined in the Xml file.
3(optional).invoke setBeanName(beanId) if the bean implements the BeanNameAware
4(optional).inovke setBeanFacoty() if the bean implements the BeanFactoryAware
5(optional for ApplicationContext). invoke setApplicationContext(), if implements ApplicationContextAware
6(optional). If bean associated with any BeanPostProcessor, postProcessBeforeInitialzation() invoked.
7(optional). If init-method was indicated, it get inovked.
8(optional).If bean associated with any BeanPostProcessor, postProcessAfterInitialzation() invoked.

Basic Load
The singleton is the default mode in the context.
following is the way to turn off this mode.
<bean class="com.cwl.IhateSingleton" id="noSingleton" singleton="false"></bean>Spring will automatically convert value to the correspondent type of the property defiend in the class with reflection.
object  member (refer other bean)

BeanFacotoryPostProcessor
Spring built-in implementation:PropertyPlaceholderConfigurer,CustomEditorConfigurer

I18N support
ResourceBundleMessageSource

lister event
In the life cycle of the bean, ApplicationContext will send lots of event, deails refer P75 spring in action.

xml 代码
  1. <bean id="foo" class="xx" singleton="false"/>  


InitAndDestroy
<bean class="" id="foo" destroy-method="destroy" init-method="init"></bean>

xml 代码
  1. <bean id="foo" class="xx" init-method="setup" destroy-method="destory"/>  


Note: the parenthesis was not included in the above configuration.

Inject dependency by Set method
primitive member
<property name="name"><value></value></property> <property name="score"></property>

xml 代码
  1. <property name="name"><value>Foo</value></property>  
  2. <property name="score"><value>22</value></property>  

 

xml 代码
  1. <property name="bar"><ref bean="bar"/></property>  


load list,set,map P54
Note: there is a limitation when loading map
The key should is confined with "String" type.

How to set Null value.
<property name="foo"><null></null></property>

xml 代码
  1. <property name="foo"><null/></property>  



Inject dependency by constructor
<constructor-arg index="x" type="java.lang.String"></constructor-arg>

xml 代码
  1. <bean id="foo" class="xx">  
  2.   <constructor-arg index="0" type="java.lang.String>  
  3.     <value>spring</value>  
  4.   </constructor-arg>  
  5. <bean>  


Automatically Loading
byName, byType, constructor,autodetect P61

Specially Bean in Spring
BeanPostProcessor
procedure
1.implement  BeanPostProcessor
2.registor bean in xml as other bean(Spring will check the bean if implement BeanPostProcessor on the fly)

分享到:
评论

相关推荐

    吴天雄--Spring笔记.doc

    Spring提供一站式解决方案,涵盖了JavaEE开发的各个层面,包括Web层(如Spring MVC)、Service层(Bean管理,声明式事务)、DAO层(JDBC模板,ORM模板)。Spring的两大核心组件是IOC(Inversion of Control,控制...

    Spring Boot核心技术 - 笔记.rar

    **Spring Boot核心技术笔记** Spring Boot是Java开发领域中一个非常受欢迎的框架,它极大地简化了创建独立、生产级别的基于Spring的应用程序的过程。Spring Boot的核心特性包括自动配置、起步依赖、内嵌Web服务器...

    百知教育spring笔记1

    - **配置文件**:通常以`.xml`扩展名存储,定义了Spring容器如何管理和配置各种Bean。 - **Bean定义**:每个Bean都由`&lt;bean&gt;`标签定义,包括`id`和`class`属性。 - `id`:唯一标识符,用于在程序中引用该Bean。 - ...

    java常用框架学习笔记

    ### Java常用框架学习笔记 #### Hibernate ##### 1.1 Hibernate 实现数据库操作步骤 - **导入所需的Jar包**:为了使用Hibernate框架,首先需要在项目中导入Hibernate库。这通常意味着添加一系列与Hibernate相关的...

    Java分布式应用学习笔记08JMX规范与各种监控场景

    ### Java分布式应用学习笔记之JMX规范与监控场景解析 #### JMX规范概览 JMX,即Java Management Extensions,是Sun Microsystems(现为Oracle的一部分)提出的用于管理系统资源的规范。这一规范允许开发者以标准化...

    springboot学习笔记.zip

    2. **依赖管理(Dependency Management)**:SpringBoot通过 starters(启动器)提供了一套完整的依赖集合,如数据访问、Web、安全等,只需在`pom.xml`或`build.gradle`中引入相应starter,所需依赖就会被自动添加。...

    j2ee精华学习笔记

    12. **JMX(Java Management Extensions)** JMX提供了一套管理框架,可以监控和管理运行中的J2EE应用和服务。 13. **安全管理** J2EE提供了基于角色的访问控制(RBAC)、容器管理的安全性和编程模型安全,确保...

    shiro核心资料笔记

    1. **配置Spring**:在Spring 配置文件中声明Shiro 的Bean,包括`SecurityManager`、Realm(认证和授权信息提供者)等。 2. **Spring AOP 集成**:通过Spring AOP 实现Shiro 的权限注解处理,将Shiro 的拦截器集成...

    neo4j安装使用笔记.docx

    - 在Spring项目中使用Neo4j时,确保所有必要的依赖已添加,并正确配置Bean扫描路径。 - 示例:`@ComponentScan(basePackages = {"appleyk.config"})` 3. **静态资源访问** - 默认情况下,静态资源如HTML页面应...

    Hibernate 笔记

    在 Spring 中使用 Hibernate,可以通过 Spring 的 Transaction Management 和 DAO Support 提供的便利性,简化事务管理和 DAO 类的编写。例如,使用 `HibernateTemplate` 或 `SessionFactoryBean` 进行配置和操作。 ...

    EJB学习笔记.rar

    EJB广泛应用于大型企业级应用,如银行系统、电子商务平台、CRM(Customer Relationship Management)系统等。在这些系统中,EJB可以作为业务逻辑层,处理复杂的事务处理、数据持久化和安全控制。 总的来说,EJB是...

    j2ee开发全程的实录

    包括会话Bean(Session Beans,处理客户端请求)和实体Bean(Entity Beans,代表数据库中的持久化对象)。 - **JMS**:对于异步通信,JMS允许应用程序通过消息队列进行通信,提高系统的可扩展性和解耦性。 - **JPA...

    工作流Activiti5学习总结

    1. **Spring集成**:Activiti5提供了Spring的适配器,可以在Spring容器中管理Activiti的bean,实现事务同步。 2. **Struts2集成**:Struts2作为MVC框架,可以处理用户界面交互,与Activiti的交互主要体现在任务的...

Global site tag (gtag.js) - Google Analytics