title: how to run test in spring mvc
body: <p>I'm trying to run some tests for my controller but somehow the @Autowire annotation is not working.</p>
  
  <p>Here is what I'm trying to do:</p>
  
  <pre><code>@WebAppConfiguration
  @ContextConfiguration("/WEB-INF/spring/app-config.xml")
  public class ClientsTest {
  
      private Client client = new Cliente();
  
      @Test
      public void test() {
  
          BindingResult result = mock(BindingResult.class);
          ClientController clientController = new ClientController();
          ModelAndView model = clientController.regClient(client, result);
          Assert.assertEquals("success", model.getViewName());
  
      }
  }
  
  @Controller
  public class ClientController {
  
      @Autowired private ClientService clientService;
  
      @RequestMapping(value="/regClient.html", method = RequestMethod.POST)
      public ModelAndView regClient(@ModelAttribute("client") @Valid Client client, BindingResult result){
  
          ModelAndView model = new ModelAndView();
  
          if(result.hasErrors())
          {
              model.setViewName("error");
          }
          else
          {
              model = clientService.regClient(client);
              model.setViewName("success");
          }
  
          return model;
      }
  }
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &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"
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/mvc
         http://www.springframework.org/schema/mvc/spring-mvc.xsd"&gt;
  
         &lt;!-- Scans the classpath of this application for @Components to deploy as beans --&gt;
         &lt;context:component-scan base-package="com.app.app_v2.web" /&gt;
  
         &lt;!-- Configures the @Controller programming model --&gt;
         &lt;mvc:annotation-driven conversion-service="conversionService"/&gt;
  
         &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
              &lt;property name="basenames"&gt;
                  &lt;list&gt;
                      &lt;value&gt;client&lt;/value&gt;
                  &lt;/list&gt;
              &lt;/property&gt;
         &lt;/bean&gt;
  
         &lt;bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"&gt;
              &lt;property name="formatters"&gt;
                  &lt;set&gt;
                      &lt;ref bean="clientFormatter"/&gt;
                  &lt;/set&gt;
              &lt;/property&gt;
         &lt;/bean&gt;
  
         &lt;bean id="clientFormatter" class="com.app.app_v2.spring.ClientFormatter"/&gt;
  
         &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
              &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"&gt;&lt;/property&gt;
              &lt;property name="prefix" value="/WEB-INF/views/"&gt;&lt;/property&gt;
              &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt;        
         &lt;/bean&gt;
  
         &lt;bean id="clientService" class="com.app.app_v2.services.ClientService"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>As far as I know the clientService is null and this is why I'm getting the exception.
  Because I don't know much about running test I'm asking for your help.</p>