Results 1 to 7 of 7

Thread: Controller + Autowiring problem

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    7

    Default 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. #2
    Join Date
    Mar 2009
    Posts
    2

    Default

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

  3. #3
    Join Date
    Aug 2009
    Posts
    9

    Default

    I'm suffering from this too... any ideas??

  4. #4
    Join Date
    May 2012
    Posts
    2

    Default

    I have the same problem anyone fixed this ?

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    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).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  6. #6
    Join Date
    Aug 2012
    Posts
    3

    Default

    @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)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •