title: Reading properties file in Spring mvc 4 issues
body: <p>I am trying to read a property file in Spring mvc 4.1.6 version and I am having some issues.</p>
  
  <p>Dispatcher-servlet.xml</p>
  
  <pre><code>&lt;context:property-placeholder location="classpath:login.properties"/&gt; 
  </code></pre>
  
  <p>My class</p>
  
  <pre><code>@Component
  public class UserCheck {
  
      @Value("${server_ip}")  String server_ip;
      public String isUserPresent(String userName){
          System.out.println("server_ip: " + server_ip);
  
          return "";
  
      }
  }
  </code></pre>
  
  <p>I am getting the server_ip as null when I print the value. My login.properties is in src/main/resources folder.</p>
  
  <p>I also tried @Value("${login.server_ip}"), but then I got a different error when deploying the application. I got </p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name : Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field
  </code></pre>
  
  <p>Is there anything else that I need to do? </p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My properties file looks like below:</p>
  
  <pre><code>server_ip=192.168.1.1
  </code></pre>
  
  <p>My complete dispatcher servlet:</p>
  
  <pre><code>&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:mvc="http://www.springframework.org/schema/mvc"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc   
  http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
      &lt;context:component-scan base-package="com.company"&gt;&lt;/context:component-scan&gt;
      **&lt;context:annotation-config/&gt;**
      &lt;mvc:annotation-driven /&gt;
  
      &lt;mvc:resources mapping="/**" location="/" /&gt;
      &lt;context:property-placeholder location="classpath:login.properties"/&gt; 
  
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name = "prefix" value="/WEB-INF/jsp/" /&gt;
          &lt;property name = "suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
      &lt;bean class="org.springframework.context.support.ResourceBundleMessageSource"
          id="messageSource"&gt;
          &lt;property name="basename" value="messages" /&gt;
      &lt;/bean&gt;
  This was added for testing**********************
  &lt;bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"&gt;
          &lt;property name="ignoreUnresolvablePlaceholders" value="true"/&gt;
          &lt;property name="locations"&gt;
            &lt;list&gt;
              &lt;value&gt;classpath:application.properties&lt;/value&gt;
            &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>My web.xml</p>
  
  <pre><code>&lt;!DOCTYPE web-app PUBLIC
   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd" &gt;
  
  &lt;web-app&gt;
    &lt;display-name&gt;test&lt;/display-name&gt;
    &lt;servlet&gt;
          &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>EDIT 3:</strong> My controller class with the @PostConstruct method</p>
  
  <pre><code>@Controller
  @SessionAttributes("userData")
  public class UserController {
  
      @Autowired
      @Value("${server_ip}")  
      String server_ip;
      @Value("${username}")   
      String username;
  
  
  
      public @ResponseBody
      @RequestMapping(value = "/validateuser")
      String validateUser(@RequestParam("user") String user){
          //UserCheck userCheck = new UserCheck();
          //String test = userCheck.isUserPresent(user);
          return "";
  
      }//validateUser
  
      @PostConstruct
      public void init(){
          System.out.println("server_ip in inti: " + server_ip);
          System.out.println("username: " + username);
  
      }
  
  }
  </code></pre>