Spring: How to organize application + web contexts?

Scenario:

  • Launch the application and load ClassPathXmlApplicationContextin main (), this will launch the Jetty web application.
  • dispatcher servlet loads a XmlWebApplicationContext
  • servlet manager is looking WEB-INF/applicaitonContext.xmlto load as root context

I'm just trying to figure out contexts.

  • Should I use the 3 contexts listed above?
  • Should I use 1st context as root context and not allow dispatcher to load by default WEB-INF/applicationContext?
  • Should I create a relationship between parents and children between 1st and 3rd contexts? (this is done for me between contexts No. 2 and No. 3 dispatcher servlet)

I just don’t quite understand how these contexts relate to each other, I just need a short summary.

+3
source share
1 answer

Context # 1 is not related to other contexts at all, it's just detailed information on how you start your web server (Jetty). Contexts # 2 and # 3 are somewhat explained in the Spring reference documentation .

  • Context # 2 is loading from WEB-INF/[servlet-name]-servlet.xml. Since there can be many DispatcherServlets, there can be more than one such context in one webapp for different servlets.
  • # 3 WEB-INF/applicationContext.xml, ( ContextLoaderListener). () -. , - beans beans.

, , . , , , Spring webapp.

:

№ 3, beans . , (, - ).

# 3: beans -. Spring ContextLoader, , Jetty webapps. , .

, # 1 Java- , Jetty. 100% . Spring applicationContext Jetty.

+7

Source: https://habr.com/ru/post/1771063/


All Articles