I have a webapp in which I define the basic dispatcher-servlet
context in web.xml and it loads the applicationContext
.
I had messageSource
defined in dispatcher-servlet
and was injecting it to controllers fine.
I also have my services defined in applicationContext
and I can inject them into my controllers (defined in dispatcher-servlet
context).
But when I moved my definition for messageSource
to the applicationContext
so that some services could resolve messages the dispatcher-servlet
context shows that it's not finding a messageSource
bean and is using the default, thus the controllers get the wrong bean injected.
Any idea why the messageSource definition in applicationContext
wouldn't be visible to the dispatcher-servlet
context?
I see that my messageSource bean is loaded in the
applicationContext
section of the logs:
2058 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'messageSource'
2058 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'messageSource'
...
2082 [main] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Using MessageSource [mycommons.spring.ResourceBundleMessageSourceWithDefaultResolution: basenames=[messages]]
I see this log in the loading of dispatcher-servlet
:
3858 [main] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@55611ed3]