Permalink
Browse files

Move servlet context to classpath and remove root-context (which just…

… imports another)
  • Loading branch information...
1 parent 7b53d0e commit 752758b184584525fd275be0f4171a90fcf481e1 @nealeu nealeu committed Mar 18, 2012
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
-
- <!-- Root Context: defines shared resources visible to all other web components -->
-
- <import resource="classpath*:fuzzy-repository-context.xml"/>
-</beans>
@@ -49,18 +49,13 @@
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
+ <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<!-- Location of Java @Configuration classes that configure the components that makeup this application -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.fuzzydb.samples.config</param-value>
</context-param>
- <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
-<!-- <context-param> -->
-<!-- <param-name>contextConfigLocation</param-name> -->
-<!-- <param-value>/WEB-INF/spring/root-context.xml</param-value> -->
-<!-- </context-param> -->
-
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
@@ -72,7 +67,7 @@
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
+ <param-value>classpath:spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
@@ -12,12 +12,26 @@
import org.junit.runner.RunWith;
/**
- * Test that our Spring context is set up correctly
+ * Test that our Spring context is set up correctly. This is not as easy as it should be. I want:
+ * <pre>
+ * {@code @ContextConfiguration}(
+ * locations = {"root-context.xml"},
+ * child = {@code @ContextConfiguration}(locations = "/WEB-INF/servlet.xml")
+ * )
+ * </pre>
+ * This would produce a child servlet context with a parent. It's almost impossible to correctly test
+ * servlet controller configurations without this.<br>
+ * This approach would also allow a more fine grained {@code @DirtiesContext} behaviour if also providing a
+ * name attribute on each context (i.e. name="root", name="servlet")
+ *
+ * In XML, <parent classes="..." or resources="..." /> would create a parent classloader. Unfortunately, parents are expected to already
+ * exist. siblings would be possible... no.. wait. I could create an application context, initialise it, and then register every concrete bean...
+ *
* @author Neale
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations={"classpath:fuzzy-repository-context.xml","classpath:controllers.xml"})
+@ContextConfiguration(locations={"classpath:test-context.xml"})
public class SearchControllerIntegrationTest {
@Autowired

0 comments on commit 752758b

Please sign in to comment.