Announcement Announcement Module
Collapse
No announcement yet.
Cannot create a bean named messageSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


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

      Comment


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

        Comment


        • #5
          Thanks Marten.

          Comment

          Working...
          X