Making use of autoProxyCreator!

slightly modifying the previous example!

beans.xml
<?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.xsd">
 
    <bean id="foo" class="biz.tugay.springaopexamples.foo.FooImpl"/>
    <bean id="bar" class="biz.tugay.springaopexamples.bar.BarImpl"/>
 
    <bean id="barAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
        <property name="advice" ref="bar"/>
        <property name="mappedName" value="foo"/>
    </bean>
 
    <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="proxyTargetClass" value="true"/>
        <property name="beanNames">
            <list>
                <value>foo</value>
            </list>
        </property>
        <property name="interceptorNames">
            <list>
                <value>barAdvisor</value>
            </list>
        </property>
    </bean>
</beans>

App.java
package biz.tugay.springaopexamples;
 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
import biz.tugay.springaopexamples.foo.Foo;
 
public class App {
 
    public static void main(String[] args) {
        final ApplicationContext appContext 
            = new ClassPathXmlApplicationContext("beans.xml");
        final Foo fooProxy = appContext.getBean("foo", Foo.class);
        fooProxy.foo();
        System.out.println(fooProxy);
    }
}

Execution
MacBook-Pro:springaopexamples koraytugay$ mvn clean install exec:java -q
Nov 19, 2017 2:40:24 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2764e13b: startup date [Sun Nov 19 14:40:24 CET 2017]; root of context hierarchy
Nov 19, 2017 2:40:24 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
BarImpl#bar
FooImpl#foo
biz.tugay.springaopexamples.foo.FooImpl@5fdbf01e