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

  • Controller + Autowiring problem

    Hi,

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

    The Controller code is:
    Code:
     (at)Autowired
        protected ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource;
    The bean definition in the application-context.xml file is:
    Code:
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
            <property name="basename" value="WEB-INF/i18n/messages"/>
            <property name="cacheSeconds" value="1"/>
            <property name="defaultEncoding" value="UTF-8"/>
    </bean>
    The controller definition is:
    Code:
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="interceptors">
                <list>
                    <ref bean="localeChangeInterceptor"/>
                </list>
            </property>
            <property name="mappings">
                <value>
                    /ajax/add_person.xml=addPersonController
                </value>
            </property>
        </bean>
    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 org.springframework.context.support.ReloadableReso urceBundleMessageSource com.treert.web.ajax.AddPersonController.messageSou rce; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [org.springframework.context.support.ReloadableReso urceBundleMessageSource] is defined: Unsatisfied dependency of type [class org.springframework.context.support.ReloadableReso 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.

    Comment


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

      Comment


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

        Comment


        • #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).

          Comment


          • #6
            @Marten:
            (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)

            Comment


            • #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.

              Comment

              Working...
              X