title: JUnit, Spring Context and Webflow
body: <p>I'm trying to configure JUnit to work with Spring, but I cannot.
  My problem is that it doesn't find the webflow files, so it fails the execution.
  However, this sounds strange to me, because I'm not actually testing webflow stuff! I want to start from the controller to the database.
  So, this is what I'm doing</p>
  
  <p>I create a test class this way:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = {"classpath:/web-application-config.xml"})
  public class MyControllerToTest {
          @Autowired
      private MyController ctr;
  
      @Test
      ....
  }
  </code></pre>
  
  <p>In classpath, I inserted src/main/resources, where the web-application-config.xml is located. Here its content:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
         http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
  &lt;!-- Scans for application @Components to deploy --&gt;
  &lt;context:component-scan base-package="com.infoone.mycontrollerpackage"/&gt;
  
  &lt;!-- Imports the configurations of the different infrastructure systems of the application --&gt;
  &lt;import resource="webflow-config.xml" /&gt;
  &lt;import resource="webmvc-config.xml" /&gt;
  &lt;import resource="data-access-config.xml" /&gt;
  &lt;import resource="repository-config.xml" /&gt;
  &lt;import resource="security-config.xml" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>When I run as JUnit the MyControllerToTest class, I get the following:</p>
  
  <pre><code>ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener
  [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@6419fa] to prepare test instance [com.infoone.myapp.MyControllerToTest@10036f2]
  java.lang.IllegalStateException: Failed to load ApplicationContext
  ...
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowExecutor': Cannot resolve reference to bean 'flowRegistry' while setting bean property 'flowDefinitionLocator'; nested exception is         org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowRegistry': Invocation of init method failed; nested exception is java.lang.IllegalStateException: An I/O Exception occurred resolving the flow location pattern '/**/*-flow.xml'
  ...
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowRegistry': Invocation of init method failed; nested exception is java.lang.IllegalStateException: An I/O Exception occurred resolving the flow location pattern '/**/*-flow.xml'
  ...
  Caused by: java.lang.IllegalStateException: An I/O Exception occurred resolving the flow location pattern '/**/*-flow.xml'
  ...
  Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/flows/] cannot be resolved to URL because it does not exist[/code]
  </code></pre>
  
  <p>Maybe, you also need my web-flow-config file, also located in src/main/resources (whereas my flows are in WEB-INF/flows/*<em>/</em>.xml, but which I also tried to move to src/main/resources with the same results):</p>
  
  <pre><code>    &lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:webflow="http://www.springframework.org/schema/webflow-config"
     xmlns:faces="http://www.springframework.org/schema/faces"
     xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
         http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd
         http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.2.xsd"&gt;
  
  &lt;!-- Executes flows: the central entry point into the Spring Web Flow system --&gt;
  &lt;webflow:flow-executor id="flowExecutor"&gt;
      &lt;webflow:flow-execution-listeners&gt;
          &lt;webflow:listener ref="facesContextListener"/&gt;
          &lt;webflow:listener ref="securityFlowExecutionListener" /&gt;
          &lt;webflow:listener ref="icefacesFlowListener" /&gt;
          &lt;webflow:listener ref="myFlowListener" /&gt;
          &lt;webflow:listener ref="myExceptionListener" /&gt;
      &lt;/webflow:flow-execution-listeners&gt;
  &lt;/webflow:flow-executor&gt;
  
  &lt;!-- The registry of executable flow definitions --&gt;
  &lt;webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows"&gt;
      &lt;webflow:flow-location-pattern value="/**/*-flow.xml" /&gt;
  &lt;/webflow:flow-registry&gt;
  
  &lt;!-- Configures the Spring Web Flow JSF integration --&gt;
  &lt;faces:flow-builder-services id="facesFlowBuilderServices" development="true" /&gt;
  
  &lt;!-- Installs a listener that creates and releases the FacesContext for each request. --&gt;
  &lt;bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/&gt;
  
  &lt;!-- Installs a listener to apply Spring Security authorities --&gt;
  &lt;bean id="securityFlowExecutionListener" class="org.springframework.webflow.security.SecurityFlowExecutionListener" /&gt;
  
  &lt;bean id="icefacesFlowListener" class="com.icesoft.spring.security.WebflowListener" /&gt;
  
  &lt;bean id="myFlowListener" class="com.infoone.myapp.spring.webflow.AutowiringFlowExecutionListener" /&gt;
  
  &lt;bean id="myExceptionListener" class="com.infoone.myapp.exception.MyExceptionListener" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Please consider that I'm also using JSF and Icefaces (which I don't want to test via JUnit at the moment).</p>
  
  <p>Thank you!</p>