We have a clear abstraction between the service level configurations and the layer context, and we load them as shown below.
Root application context: <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value> </context-param> Web application context: <servlet> <servlet-name>lovemytasks</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/mmapp-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
Now we are trying to introduce SPRING MVC TEST FRAMEWORK to test our application.
To do this, I will need to configure the same environment as my real web application.
How can i do this?
I tried the below configuration of my test to load both contexts.
@ContextConfiguration(locations = { "classpath*:META-INF/spring/applicationContext*.xml", "file:src/main/webapp/WEB-INF/spring/mmapp-servlet.xml" })
But his mistake is because
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Duplicate <global-method-security> detected.
We defined global security both in the context of the root application and in the context of web applications.
Note. The above problem will not appear when starting my web application. This only happens when I run the MVR SPRING test.
I tried to remove my global security and one place, and then proceed with errors with conversion services when performing my tests. Which warned me that I am not loading the context, as the real SPRING application does.
Now, I would like to configure the SPRING MVC test environment to use or work in the same way that the SPRING web application environment works. Can anyone suggest how I can achieve this?
source share