Results 1 to 5 of 5

Thread: Cannot create a bean named messageSource

  1. #1

    Question Cannot create a bean named messageSource

    I am trying to create a bean named messageSource. Below is my xml for bean creation.

    Code : spring.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd>
        
       <bean id="messageSource" class="com.MessageSource">
            <property name="message" value="${myName}" />
        </bean>
    </beans>
    When I tried to load the application context using
    Code:
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
    it fails giving following exception.
    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'messageSource' must be of type [org.springframework.context.MessageSource], but was actually of type [com.MessageSource]
    I was able to get the application working by giving different name for messageSource bean (e.g. myMessageSource) .

    But why is it throwing this exception ? Is it expected behaviour ?

    Regards,
    prithvi

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Is it expected behaviour ?
    Yes it is expected behavior... 'messageSource' is one of the few names spring uses to lookup certain infrastructure beans and this bean has to be a org.springframework.context.MessageSource.
    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

  3. #3

    Default

    Quote Originally Posted by Marten Deinum View Post
    'messageSource' is one of the few names spring uses to lookup certain infrastructure beans and this bean has to be a org.springframework.context.MessageSource.
    Thanks Marten.

    Can you tell what are infrastructure beans ? or can you give me a link where I can read about these.

    Thanks

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    The reference guide is your source for that... Which beans are detected by name or by type also depends on your type of application and which loading mechanism you use. Some of the names are dictated by the ApplicationContext others 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

  5. #5

    Default

    Thanks Marten.

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
  •