title: Spring Junit test returns 404 error code
body: <p>I am creating one Spring Junit class for testing one of my rest api. But when I called it, it return me 404 and the test case failed.
  The Junit test class is:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @WebAppConfiguration
  @ContextConfiguration(locations={"classpath:config/spring-commonConfig.xml"})
  public class SampleControllerTests {
  
  public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(
          MediaType.APPLICATION_JSON.getType(),
          MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
  
  private MockMvc mockMvc;
  @Autowired
  private WebApplicationContext webApplicationContext;
  
  @Before
  public void setup() {
      this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
  }
  
  @Test
  public void testSampleWebService() throws Exception {
      mockMvc.perform(post("/sample/{userJson}", "{\"id\":\"102312121\",\"text\":\"Hi user\",\"key\":\"FIRST\"}"))
      .andExpect(status().isOk())
      .andExpect(jsonPath("$result", is("Hello ")))
      .andExpect(jsonPath("$answerKey", is("")));
  }   
  }
  </code></pre>
  
  <p>The RestController class is:</p>
  
  <pre><code>@RestController
  public class SampleController {
  
  private static final Logger logger = LoggerFactory.getLogger(SampleController.class);
  Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").create();
  
  @Autowired private SampleService sService;
  
  
  @RequestMapping(value = "${URL.SAMPLE}", method = RequestMethod.POST)
  @ResponseBody
  public String sampleWebService(@RequestBody String userJson){
      String output="";
      try{
          output = sService.processMessage(userJson);
      }
      catch(Exception e){
          e.printStackTrace();
      }
      return output;
  }
  }   
  </code></pre>
  
  <p>I am loading the url string from property file. This way I am not hard coded the url in controller class but mapped it dynamically, so that is the reason I am loading the property files via class which I mentioned below.</p>
  
  <blockquote>
    <p>"URL.SAMPLE=/sample/{userJson}"</p>
  </blockquote>
  
  <p>The class which reads the property file where url is defined:</p>
  
  <pre><code>@Configuration
  @PropertySources(value = {
      @PropertySource("classpath:/i18n/urlConfig.properties"),
      @PropertySource("classpath:/i18n/responseConfig.properties")
  })
  public class ExternalizedConfig {
  
  @Bean
  public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
      return new PropertySourcesPlaceholderConfigurer();
  }
  }
  </code></pre>
  
  <p>The error code 404 means, it is connect to server but not getting the source we requested.
  Can anybody tell me what exactly the issue is?</p>
  
  <p>Thanks,
  Atul</p>