Macros

给我一支烟!请所有烦恼都能过往如云烟!

导航

Spring之:BeanNameAutoProxyCreator的使用与配置

配置如下:
<beans>
   <bean id="BeanNameAutoProxyCreator"
      class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
      <property name="beanNames">
         <value>woman*</value>
      </property>
      <property name="interceptorNames">
         <list>
                      <value>myAdvice</value>
         </list>
      </property>
   </bean>
   <bean id="woman" class="entity.Woman" >
      <property name="name">
         <value>java</value>
      </property>
      <property name="pass">
         <value>jdk</value>
      </property>
   </bean>
   <bean id="myInterceptor" class="advice.MyInterceptor" />
   <bean id="myAdvice" class="advice.MyAdvice" />
</beans>
调用代码如下:
InputStream is =
         HibernateTransactionTest
            .class
            .getClassLoader()
            .getResourceAsStream(
            "conf/AutoProxy.xml");
      ClassPathXmlApplicationContext classPathXmlApplicationContext =
         new ClassPathXmlApplicationContext(
            new String[] { "conf/AutoProxy.xml" });
      ApplicationContext appContext =
         (ApplicationContext) classPathXmlApplicationContext;
      Woman woman = (Woman) appContext.getBean("woman");
      System.out.println("woman.getName()=" + woman.getName());

posted on 2005-11-04 18:30  Macros  阅读(2279)  评论(0)    收藏  举报