Using the ClassPa class thanksmlApplicationContext in a stand-alone Java class

While I am not familiar with Spring. I saw the code below in one of the standalone java projects that I have on my system. Could you help me understand the code below. I can not see spring.xml in the project - is it something that should be there and missing?

appContext = new ClassPathXmlApplicationContext(new String[] { "classpath*:/META-INF/spring.xml", "classpath*:myapplication-application-context.xml" }); 
+6
source share
2 answers

The syntax classpath* means that Spring will look for the classpath for all resources called /META-INF/spring.xml and myapplication-application-context.xml and combine them in context. This includes viewing JAR files inside the project, so it may not be visible in your main project files.

+8
source

Spring's core functions revolve around ApplicationContext , which is the "Central Interface for Application Configuration." the interface is implemented using ClassPathXmlApplicationContext , which helps you determine contextual definitions from your class path. If you specify the class path *.

As @skaffman explains, your application loads from context definitions in the above files. that is, all Spring beans are initialized, and dependency injection is performed as needed.

If you are working with web applications, Spring has the corresponding web application context loaded by XmlWebApplicationContext

+6
source

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


All Articles