Announcement Announcement Module
No announcement yet.
DefaultAdvisorAutoProxyCreator Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • DefaultAdvisorAutoProxyCreator

    I am able to construct a domain object instance as follows:

    Person person = (Person) acbf.autowire(Person.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    Person person2 = (Person) acbf.applyBeanPostProcessorsBeforeInitialization(person, "person");
    This works fine, being autowired correctly and BeanPostProcessors being called on the instance. However, I'd like to have DefaultAdvisorAutoProxyCreator (DAAPC) process the instance as well, as I have a security-related Advisor defined in the context. Debug logging suggests DAAPC never gets called, although it is called for standard container-managed beans created during initialization and implements BeanPostProcessor. I did notice the package note, "autoproxying is not supported for BeanFactory implementations, as post-processing is automatic only for application contexts", which may be related.

    Would someone please elaborate on how to get DAAPC to process domain object instances?

  • #2
    No need to respond to this question anymore. I ended up using AspectJ to add a security advice to domain object instances when they're created.


    • #3
      After getting my security advice operational under AspectJ (now in Acegi Security CVS for those interested), I went back to the original approach as the AspectJ Eclipse incremental build integration has problems.

      This is the answer to my original post:

      1. Ensure DefaultAdvisorAutoProxyCreator is added to the bean factory you're actually using to call applyBeanPostProcessorsAfterInitialization (or navigate to the parent bean factory which contains it).

      2. Ensure you're calling the AFTER initialization method, not the before initialization method. ie acbf.applyBeanPostProcessorsBeforeInitialization(p erson, "person");

      If a wrapper is returned from applyBeanPostProcessorsBeforeInitialization, as you'd expect if the instance is autoproxied, it will be castable to Advised or any interface your domain object implements.