Listing 7-16. Configuring Introductions with ProxyFactoryBean
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="bean" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<bean  class="com.apress.prospring3.ch7.introductions.TargetBean">
<property name="name">
<value>Clarence Ho</value>
</property>
</bean>
</property>
<property name="interceptorNames">
<list>
<value>advisor</value>
</list>
</property>
<property name="proxyTargetClass">
<value>true</value>
</property>
</bean>
<bean id="advisor" class="com.apress.prospring3.ch7.introductions.IsModifiedAdvisor"/>
</beans>
As you can see from the configuration, we use the IsModifiedAdvisor class as the advisor for the
ProxyFactoryBean, and because we do not need to create another proxy of the same target object, we use
an anonymous declaration for the target bean. Listing 7-17 shows a modification of the previous
introduction example that obtains the proxy from the ApplicationContext.
Listing 7-17. The IntroductionConfigExample Class
package com.apress.prospring3.ch7.introductions;
import org.springframework.context.support.GenericXmlApplicationContext;
public class IntroductionConfigExample {
public static void main(String[] args) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("classpath:introductions.xml");
ctx.refresh();
TargetBean bean = (TargetBean) ctx.getBean("bean");
IsModified mod = (IsModified) bean;
// test interfaces
System.out.println("Is TargetBean?: " + (bean instanceof TargetBean));
System.out.println("Is IsModified?: " + (bean instanceof IsModified));
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home