title: @PostConstuct does not appear to work and @autowire gives an error
body: <p>I am new to spring and am creating a  spring web application.
  The application I'm writing has a <code>Class PreLoadService</code>. In this class is a method defined with <code>@PostConstruct</code> that calls a DAO to load the data. The DAO instance is declared in the class with the <code>@autowired</code>.</p>
  
  <p>The Controller for the JSP then declares an instance of the <code>PreLoadService</code> and calls the getter to retrieve the data that should have been loaded in the <code>@PostConstruct</code>. The data is never loaded and an exception is also thrown on the <code>@autowired</code>.</p>
  
  <p>Since this did not work I tried a simple Hello World version to write a message and received the same issue. I will post this. In the WEB_INF folder I have a <code>web.xml</code> and a <code>spring3-servlet.xml</code>. In the SRC folder I have an <code>applicationContext.xml</code>. I am running on Tomcat 7.</p>
  
  <p><strong>Web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  id="WebApp_ID" version="2.5"&gt;
  &lt;display-name&gt;Spring3MVC&lt;/display-name&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;webAppRootKey&lt;/param-name&gt;
      &lt;param-value&gt;root.webpath&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;spring3&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;spring3&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.html&lt;/url-pattern&gt;
       &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;&lt;/web-app&gt;
  </code></pre>
  
  <p><strong>spring3-servlet.xml</strong></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:p="http://www.springframework.org/schema/p"
  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-3.0.xsd
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
   &lt;!--will allow Spring to load all the components from package and all its child packages--&gt;    
  &lt;mvc:annotation-driven /&gt;
  &lt;context:component-scan
      base-package="com.nikki.spring3.controller" /&gt;
  &lt;!-- will resolve the view and add prefix string /WEB-INF/jsp/ and suffix .jsp to the view in ModelAndView.  --&gt;       
  &lt;bean id="viewResolver"
      class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
      &lt;property name="viewClass"
          value="org.springframework.web.servlet.view.JstlView" /&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>applicationContext.xml</strong></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:p="http://www.springframework.org/schema/p"
  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-3.0.xsd
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
     &lt;mvc:annotation-driven/&gt;   
   &lt;context:component-scan base-package="com.nikki.spring3"&gt;
   &lt;context:exclude-filter    expression="org.springframework.stereotype.Controller" type="annotation"/&gt;
  &lt;/context:component-scan&gt; 
  &lt;bean id="helloWorldService" 
      class="com.nikki.spring3.beansit.HelloWorldService"&gt;
      &lt;property name="message" value="Preloading Init Config and Data" /&gt;
  </code></pre>
  
  <p> </p>
  
  <p><strong>HelloWorldService</strong></p>
  
  <pre><code>public class HelloWorldService {
  
   private String message;
  
     public void setMessage(String message){
        this.message  = message;
     }
  
     public String getMessage(){
        System.out.println("Your Message : " + message);
        return message;
     }
     @PostConstruct
     public void init(){
        System.out.println("Bean is going through init.");
     }
     @PreDestroy
     public void destroy(){
        System.out.println("Bean will destroy now.");
     }
  }
  </code></pre>
  
  <p><strong>HelloWorldController</strong></p>
  
  <pre><code> @Controller
  public class HelloWorldController {
      @Autowired 
      HelloWorldService helloWorldService;
  /* RequestMapping annotation tells Spring that this Controller should
   *  process all requests beginning with /hello in the URL path. 
   *  That includes /hello/* and /hello.html.
   */
      @RequestMapping("/hello")
      public ModelAndView helloWorld() {
  
          String message =helloWorldService.getMessage();
                  //"Hello World, Spring 3.0!";
          return new ModelAndView("hello", "message", message);
      }
  }
  </code></pre>
  
  <p><strong>Error Message</strong></p>
  
  <pre><code>Exception
  SEVERE: StandardWrapper.Throwable  org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': 
  Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'helloWorldController': 
  Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:
  Could not autowire field: com.nikki.spring3.beansit.HelloWorldService com.nikki.spring3.controller.HelloWorldController.helloWorldService; 
  nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
  No matching bean of type [com.nikki.spring3.beansit.HelloWorldService] 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)}
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
  </code></pre>
  
  <p>I appreciate any help. Thanks.</p>