码迷,mamicode.com
首页 > 其他好文 > 详细

2、一些配置

时间:2017-01-18 21:20:41      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:turn   property   throws   etc   initial   location   exp   ase   public   

1、导入资源文件

<context:property-placeholder location="classpath:db.properties"/>

用${}来引用

2、SpEL

使用#{}

3、 bean生命周期方法

 1 public class Bean1 {
 2 
 3     public Bean1() {
 4         System.out.println("Bean1()");
 5     }
 6 
 7     public void init() {
 8         System.out.println("init...");
 9     }
10 
11     @Override
12     public String toString() {
13         return this.getClass().getName();
14     }
15 
16     public void destroy() {
17         System.out.println("destroy...");
18     }
19 
20 }

配置:

1 <bean id="bean1" class="demo.Bean1" init-method="init" destroy-method="destroy" />

4、配置bean的时parent、p命名空间和depends-on。。。的使用

5、bean的后置处理器

 1 public class MyBeanPostProcessor implements BeanPostProcessor {
 2 
 3     @Override
 4     public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
 5         System.out.println("postProcessBeforeInitialization: " + beanName);
 6         return bean;
 7     }
 8 
 9     @Override
10     public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
11         System.out.println("postProcessAfterInitialization: " + beanName);
12         return bean;
13     }
14 
15 }

  配置:

1 <bean class="demo.MyBeanPostProcessor" />

6、在classpath中扫描组件

1 <context:component-scan base-package="" resource-pattern="">
2     <context:include-filter type="" expression=""/>
3     <context:exclude-filter type="" expression=""/>
4 </context:component-scan>

2、一些配置

标签:turn   property   throws   etc   initial   location   exp   ase   public   

原文地址:http://www.cnblogs.com/upsidedown/p/6296980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!