Announcement Announcement Module
No announcement yet.
Controller + Autowiring problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controller + Autowiring problem


    I have a problem autowiring a bean to a controller. The autowiring is done through annotations.

    The Controller code is:
        protected ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource;
    The bean definition in the application-context.xml file is:
    <bean id="messageSource" class=""> 
            <property name="basename" value="WEB-INF/i18n/messages"/>
            <property name="cacheSeconds" value="1"/>
            <property name="defaultEncoding" value="UTF-8"/>
    The controller definition is:
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="interceptors">
                    <ref bean="localeChangeInterceptor"/>
            <property name="mappings">
    The error I get when trying to deploy the application in Tomcat is:
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'addPersonController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: protected urceBundleMessageSource com.treert.web.ajax.AddPersonController.messageSou rce; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [ urceBundleMessageSource] is defined: Unsatisfied dependency of type [class urceBundleMessageSource]: expected at least 1 matching bean

    I have another bean defined in the same application-context file, specified using the same autowiring annotation and that one works just fine. What is the problem with this reloadableResourceBundleMessageSource bean?
    Thank you for your time....

  • #2
    I have the same problem , please someone throw some lights on it.


    • #3
      I'm suffering from this too... any ideas??


      • #4
        I have the same problem anyone fixed this ?


        • #5
          Hmm reviving old threads (ancient?) threads?!

          1) Don't use the concrete implementation use MessageSource interface instead
          2) Make sure you don't scan twice for your beans (once in the ContextLoaderListener and once in the DispatcherServlet, the first will fail to load as in general your MessageSource is defined by the DispatcherServlet).


          • #6
            (1) fixed my load errors, but I have a feeling (2) is related to my problem because I am getting an empty DelegatingMessageSource...

            Can you expand a bit about (2)? how do we make sure we don't "scan twice"? (hint: i'm a bit of a noob at spring so elaborate as much as you want)


            • #7
              Originally posted by thezuck
              Can you expand a bit about (2)? how do we make sure we don't "scan twice"? (hint: i'm a bit of a noob at spring so elaborate as much as you want)
              That question has been answered numerous times before on the forum so please use the search for that.

              In short your ContextLoaderListener shouldn't scan for @Controller and your DispatcherServlet should only scan for @Controller.