title: Spring MVC Test In Fitnesse
body: <p>I have a probleme with Fitnesse Integration with Spring MVC . </p>
  
  <p>My use case to test is the authentication : </p>
  
  <p>I have a generic Fixture that load spring Context : </p>
  
  <pre><code>public abstract class GenericSpringFixture extends GenericBelFixture {
  
  protected static AutowireCapableBeanFactory beanFactory;
  protected static ClassPathXmlApplicationContext context;
  
  static {
      initSpring();
  }
  
  public static void initSpring() {
      if ((context == null) || !context.isActive()) {
          context = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-fitnesse-common.xml");
          beanFactory = context.getAutowireCapableBeanFactory();
      }
  }
  
  public GenericSpringFixture() {
      beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
  }
  
  public static AutowireCapableBeanFactory returnBeanFactory() {
      return beanFactory;
  }
  }
  </code></pre>
  
  <p>The applicationContext-fitnesse-common.xml file is loading all dependencies of My plateform and this include my servlet(Spring Mvc Files) config . </p>
  
  <p>My fixture code is : </p>
  
  <pre><code>public class IdentificationUtilisateur extends GenericSpringFixture{
  
  @Autowired
  private WebApplicationContext webApplicationContext;
  
  @Autowired
  private FilterChainProxy springSecurityFilterChain;
  
  private MockMvc mockMvc;
  
  public void seLogerAvecIdentifiantEtMotDePasse(String identifiant,
          String motDePasse) {
      this.mockMvc = MockMvcBuilders
              .webAppContextSetup(this.webApplicationContext)
              .addFilters(this.springSecurityFilterChain).build();
  }
  
  public void accesReussi() throws Exception{
      mockMvc.perform(
              post("/j_spring_security_check")
                      .param("j_username", "bilal")
                      .param("j_password", "Pa1234567"));
  }
  }
  </code></pre>
  
  <p>The problem is that spring is not able to find any webApplicationContext . </p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'ma.awb.ebk.bel.web.fixture.authentication.IdentificationUtilisateur':
    Injection of autowired dependencies failed; nested exception is
    org.springframework.beans.factory.BeanCreationException: Could not
    autowire field: private
    org.springframework.web.context.WebApplicationContext
    ma.awb.ebk.bel.web.fixture.authentication.IdentificationUtilisateur.webApplicationContext;
    nested exception is
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    qualifying bean of type
    [org.springframework.web.context.WebApplicationContext] found for
    dependency: expected at least 1 bean which qualifies as autowire
    candidate for this dependency. Dependency annotations:
    {@org.springframework.beans.factory.annotation.Autowired(required=true)}</p>
  </blockquote>
  
  <p>The only difference between My Slim fixture and my test Spring mvc is that in my test MVC , i am on a junit context and i have this annotation enabled on my Junit test : </p>
  
  <pre><code>@WebAppConfiguration
  </code></pre>
  
  <p>Thanks for your Help . </p>