Announcement Announcement Module
Collapse
No announcement yet.
can AOP be applied in webapplicationcontext? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • can AOP be applied in webapplicationcontext?

    Suppose I built a web program with spring-web mvc and the servlet name is set "demo" with class DispatcherServlet in "web.xml". In the "demo-servlet.xml" file there are configurations of the beans, including some controllers to handle requests (extend the MultiActionController).

    If I want to enable AOP to a controller bean defined in the "demo-servlet.xml" file, how can I do it? I have tried the @aspectJ annotations like the way to enable AOP in applicationContent.xml, but it did not work.

    Thanks!

  • #2
    In this case, Spring creates two application contexts.

    1. First one for your application layer (applicationContent.xml) where you have AOP configuration (This is called as "Parent context")
    2. Second one for your web-layer (demo-servlet.xml) where you have controller beans defined or component scan to create all controller beans. (This is called as "Child context").

    Parent context does not have any visibility on Child context beans, but from child context, you can get Parent context beans. Hence you need to move your AOP configurations into web-layer (demo-servlet.xml) context in order to apply your AOP advice on controller beans at web layer as well.

    Comment

    Working...
    X