Results 1 to 3 of 3

Thread: trouble with simple BeanNameAutoProxyCreator example

  1. #1
    Join Date
    May 2005
    Posts
    20

    Default trouble with simple BeanNameAutoProxyCreator example

    I'm new to Spring, and tried to set up a BeanNameAutoProxyCreator example just to see the AOP stuff work, and I'm having some trouble.

    My xml looks like this:

    Code:
        <bean id="sampleSpringObject" class="com.agentscape.associate.test.SampleSpringObjectImpl">
            <property name="name" value="Joe"/>
            <property name="age" value="28"/>
        </bean>
    
        <bean id="autoLogger" class="com.agentscape.associate.test.AutoLoggerAdvice"/>
    
        <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
            <property name="interceptorNames">
                <value>autoLogger</value>
            </property>
            <property name="beanNames">
                <value>*</value>
            </property>
        </bean>
    From the examples I've seen, I would've expected my before method on my AutoLoggerAdvice class to get called for any methods on my SampleSpringObject, but nothing seems to get called. I call the getters on my SampleSpringObject, and I don't see my before method get called.

    My Advice class is very simple, just:
    Code:
    public class AutoLoggerAdvice implements MethodBeforeAdvice &#123;
    
        public void before&#40;Method method, Object&#91;&#93; args, Object target&#41; throws Throwable &#123;
            System.out.println&#40;"method.getName&#40;&#41; = " + method.getName&#40;&#41;&#41;;
        &#125;
    
    &#125;
    I know the advice and the bean work, because I was able to get an example working with this xml:
    Code:
        <bean id="sampleSpringObjectTarget" class="com.agentscape.associate.test.SampleSpringObjectImpl">
            <property name="name" value="Joe"/>
            <property name="age" value="28"/>
        </bean>
    
        <bean id="autoLogger" class="com.agentscape.associate.test.AutoLoggerAdvice"/>
    
        <bean id="sampleSpringObject" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="proxyInterfaces">
                <list>
                    <value>com.agentscape.associate.test.SampleSpringObject</value>
                </list>
            </property>
            <property name="interceptorNames">
                <list>
                    <value>autoLogger</value>
                </list>
            </property>
            <property name="target">
                <ref bean="sampleSpringObjectTarget"/>
            </property>
        </bean>
    Do I have something wrong in my BeanNameAutoProxyCreator config that it's not picking up the methods in my SampleSpringObject?

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Posts
    107

    Default Re: trouble with simple BeanNameAutoProxyCreator example

    How are you loading it? You need to use the ApplicationContext (not the XmlBeanFactory). E.g.

    final BeanFactory beanFactory = new ClassPathXmlApplicationContext(appContextFile);

  3. #3
    Join Date
    May 2005
    Posts
    20

    Default Re: trouble with simple BeanNameAutoProxyCreator example

    Quote Originally Posted by hucmuc
    How are you loading it? You need to use the ApplicationContext (not the XmlBeanFactory). E.g.

    final BeanFactory beanFactory = new ClassPathXmlApplicationContext(appContextFile);
    That must be it. I was trying it with the XmlBeanFactory. Thanks for the tip.

Similar Threads

  1. Problem with Simple RMI Sample
    By con19m32 in forum Remoting
    Replies: 2
    Last Post: Jun 27th, 2007, 12:38 AM
  2. simple question
    By yukster in forum Security
    Replies: 6
    Last Post: Sep 19th, 2005, 07:58 AM
  3. Trouble deploying PhoneBook portlet example
    By belaran in forum Web Flow
    Replies: 1
    Last Post: Aug 2nd, 2005, 10:52 AM
  4. problem running simple aop!
    By khalidhajsaleh in forum AOP
    Replies: 2
    Last Post: Jul 27th, 2005, 01:37 PM
  5. Simple cacheing idea
    By jonmor in forum AOP
    Replies: 3
    Last Post: Feb 5th, 2005, 02:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •