Spring Aspect not executed when defined in other JAR

后端 未结 4 2091
故里飘歌
故里飘歌 2021-01-18 08:27

I have a project consisting of two subprojects which are both Spring projects and have an applicationContext.xml each.

One is a framework project (which ends up as

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 08:38

    In Spring MVC webapps, you actually have 2 contexts: the root context and the servlet's context. Be sure to configure your aspect in the servlet's context. Indeed, the servlet's context "sees" the root one - and not the other way around:

    In the Web MVC framework, each DispatcherServlet has its own WebApplicationContext, which inherits all the beans already defined in the root WebApplicationContext. These inherited beans can be overridden in the servlet-specific scope, and you can define new scope-specific beans local to a given Servlet instance.

    So your import of the framework config has to be made in the [servlet-name]-servlet.xml file rather than in the other one(s) if you want your aspects to be applied to its beans.

提交回复
热议问题