Results 1 to 6 of 6

Thread: Method interceptor in java classes not from beanfactory

  1. #1

    Default Method interceptor in java classes not from beanfactory

    Hi,

    I'm trying to use spring AOP in my project on classes that are not declared as beans in the bean factory.

    I tried the NameMatchMethodPointcutAdvisor, but I couldn't manage to get it working. I also tried out the AutoProxyCreator classes, but they only seem applicable for bean in the bean factory.

    So, is it possible to add a method interceptor in classes that are not defined in the bean factory? Any leads?

    Thanks a lot!
    Kris

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    So, is it possible to add a method interceptor in classes that are not defined in the bean factory?
    NAFAIK
    Any leads?
    AspectJ

  3. #3
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    You could also use Spring AOP programmatically.

  4. #4

    Default

    Ah, so it's possible to add a method interceptor at runtime?? Do you have an example of this? I couldn't find munh info about this in the manual.

  5. #5
    Join Date
    Jan 2005
    Location
    MD
    Posts
    31

    Default

    Kris,

    I think this is what you are looking for: http://www.springframework.org/docs/....html#aop-prog.

  6. #6

    Default

    I do it a bit differently, first, I write a config xml like this (this code shows introduction advice):

    Code:
      <bean name="beanAdvisor" class="spring.ExtensionAdvisor" singleton="false">
        <constructor-arg index="0">
    			<bean class="Application.BeanExtensionImpl" singleton="false" />
    		</constructor-arg>
        <constructor-arg index="1">
    			<value>Application.BeanExtension</value>
    		</constructor-arg>
      </bean>
      <bean name="bean" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="singleton"><value>false</value></property>
        <property name="proxyInterfaces">
          <value>Application.BeanView</value>
        </property>
        <property name="interceptorNames">
          <list>
            <value>beanAdvisor</value>
          </list>
        </property>
      </bean>
    And then use code like this to "wire" up the instance:

    Code:
       BeanView target = null;
       if&#40; context.containsBean&#40;"bean"&#41; &#41; &#123;
          target = &#40;BeanView&#41; context.getBean&#40;"bean"&#41;;
          &#40;&#40;Advised&#41; target&#41;.setTargetSource&#40;beanInstance&#41;;
       &#125;
    This allows me the flexibility of defining all the advice in a config file.

    Cheers

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. PerformanceMonitorInterceptor
    By tnist in forum AOP
    Replies: 3
    Last Post: Aug 24th, 2005, 01:39 PM
  5. Replies: 1
    Last Post: Jul 28th, 2005, 05:08 PM

Posting Permissions

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