Announcement Announcement Module
Collapse
No announcement yet.
Proxy creation and multiple XML files for application context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Proxy creation and multiple XML files for application context

    Hello,
    I have a question regarding proxy creation around beans when application context is split across multiple XML files.
    What is the order of creating beans from multiple files and creating of proxies?
    Are proxies created at the end, when all beans (defined in all xml files) are created in Spring application context?

    I am developing a Spring MVC application and I have defined the most of beans in myapp-servlet.xml.
    The DAO beans are defined in a separated XML file called database_config.xml, which is included in application context in web.xml file.

    I would like to implement logging of the methods in the DAO objects with aspects, but it seems to me that a proxy
    can't be wrapped around DAO beans if DAO beans are defined in database_config.xml.
    Are DAO beans created in application context after auto proxy creator creates proxies?

    When I move DAO beans to myapp-servlet.xml, it works.
    I am creating logging advice and auto proxy creator through lines below.
    Code:
    <bean id="loggingAdvice" class="mypackage.LoggingAdvice">
    </bean>
    	
    <bean  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    		<property name="beanNames">
    			<value>*Dao</value>			
    		</property>
    		<property name="interceptorNames">
    			<list>
    				<value>loggingAdvice</value>				
    			</list>
    		</property>		
    </bean>
    Thank you in advance, and sorry if this issue has already been discussed.

  • #2
    Well maybe understand how an applicationcontext works might help...

    AOP only works on beans defined/loaded in the same ApplicationContext NOT in parent or child contexts... In a web application you typically have 2 contexts, 1 root (ContextLoaderListener) and one child (DispatcherServlet). AOP configured in the root will not and cannot advice beans in the child and vice versa...

    And next time please use the search because I alone already answered this question multiple times....

    Comment


    • #3
      Hi Marten, thanks for your answer.
      I have read several of your posts regarding AOP,
      but I haven't found explanation about parent and child contexts.
      Thanks once again!

      Comment

      Working...
      X