title: No qualifying bean ... spring-webmvc: bean defined in applicationContext is not visible in ServletContext
body: <p>I have problems with beans defined in APplicationContext. (May be my problems is understanding of Application~Servlet contexts ?) </p>
  
  <p>So, I define <strong>&lt; bean id="messageSource"</strong> in :</p>
  
  <p><strong>applicationContext.xml</strong> </p>
  
  <pre><code>    &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:jpa="http://www.springframework.org/schema/data/jpa"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc 
  
  http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
          http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.
  &lt;!-- // configure manage of transactions using annotations @Transactional // --&gt;
  
  &lt;tx:annotation-driven /&gt;
  
  &lt;!-- // SPRING-SECURITY // --&gt;
  &lt;import resource="security-servlet.xml" /&gt;
  
  &lt;!-- // DB1 - Database Configuration // --&gt;
  &lt;context:property-placeholder location="/WEB-INF/spring/db.config/jdbc-db1.properties" /&gt;
  
  &lt;import resource="./db.config/DataSource-db1.xml" /&gt;
  &lt;import resource="./db.config/jpa-config-db1.xml" /&gt;
  
  &lt;!-- Auto scan the components --&gt;
  &lt;context:annotation-config /&gt;
  
  &lt;!-- // common beans for rest &amp; mvc // --&gt;
  &lt;context:component-scan base-package="abc.def.data"  /&gt;
  
  &lt;bean
      id="messageSource"
      class="org.springframework.context.support.ResourceBundleMessageSource"
  &gt;
      &lt;property
          name="basename"
          value="validation" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>also I have mvc-servlet.xml defines in web.xml as : </p>
  
  <pre><code>    &lt;!-- // MVC // --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;mvc&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;WEB-INF/spring/mvc-servlet.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;mvc&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.htm&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>In my @controller I use bean messageSource such way : </p>
  
  <pre><code>@Controller
  @RequestMapping( value = "/admin/su" )
  public class AdminSuController {
  private final Logger LOG = LoggerFactory.getLogger( getClass() );
      .....
      @Autowired
      private ResourceBundleMessageSource messageSource;
  </code></pre>
  
  <p>WHEN I define bean in mvc-servlet.xml - no problems 
  as soon as I move it to (as I understand root context for servletContext) ApplicationContext.xml (I do that to use this beans in REST-servlet.xml and other @controller-s ) I get : </p>
  
  <pre><code>#19:41:26.594 [localhost-startStop-1] ERROR 
  </code></pre>
  
  <blockquote>
    <p>o.s.web.servlet.DispatcherServlet - Context initialization failed 
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'addressController': Injection of autowired
    dependencies failed; nested exception is
    org.springframework.beans.factory .BeanCreationException: Could not
    autowire field: private
    org.springframework.context.support.ResourceBundleMessageSource
    abc.def.rest.controller.AddressController.messageSource; nested
    exception is org.sp
    ringframework.beans.factory.NoSuchBeanDefinitionException: No
    qualifying bean of type
    [org.springframework.context.support.ResourceBundleMessageSource]
    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.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE ]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]     at
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]     at
    org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663)
    ~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE]  at
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629)
    ~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE]  at
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677)
    ~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE]  at
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548)
    ~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE]  at
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489)
    ~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE]  at
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    [spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    [servlet-api.jar:3.0.FR]  at
    org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5262)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5550)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1245)
    [catalina.jar:7.0.59]     at
    org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1895)
    [catalina.jar:7.0.59]     at
    java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    [na:1.7.0]    at
    java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    [na:1.7.0]    at
    java.util.concurrent.FutureTask.run(FutureTask.java:166) [na:1.7.0]
      at
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    [na:1.7.0]    at
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    [na:1.7.0]    at java.lang.Thread.run(Thread.java:722) [na:1.7.0] Caused
    by: org.springframework.beans.factory.BeanCreationException: Could not
    autowire field: private
    org.springframework.context.support.ResourceBundleMessageSource
    abc.def.rest.controller.AddressControll er.messageSource; nested
    exception is
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    qualifying bean of type
    [org.springframework.context.support.ResourceBundleMessageSource]
    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.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELE ASE]  at
    org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE ]  ... 34 common frames
    omitted Caused by:
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    qualifying bean of type
    [org.springframework.context.support.ResourceBundleMessageSource]
    found for dependency: expected at le ast 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.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]   at
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELE ASE]  ... 36 common frames
    omitted</p>
  </blockquote>