1

I have a problem or possibly I found a bug in Spring Boot. I am not sure at the moment. I have a project with the following dependencies

  • spring-boot-starter-thymeleaf
  • spring-boot-starter-web
  • spring-boot-starter-actuator
  • spring-boot-starter-mail
  • spring-cloud-starter-bus-amqp
  • spring-cloud-starter-config
  • spring-cloud-starter-eureka

I want to use a messageSource in my Thymeleaf templates and so I set the following in my application.yml:

spring:
  messages:
    basename: de/mycompany/messages/message

and placed a message.properties and a message_de.properties in the above package. But the replacing did not work. So I debugged MessageSourceAutoConfiguration and found, that the @Conditional(ResourceBundleCondition.class) did work. It found my Resources and returned true. So I let print the debug report and found, that it says

MessageSourceAutoConfiguration
      - Bundle found for spring.messages.basename: de/mycompany/messages/message (MessageSourceAutoConfiguration.ResourceBundleCondition)
      - @ConditionalOnMissingBean (types: org.springframework.context.MessageSource; SearchStrategy: all) found the following [messageSource] (OnBeanCondition)

So there is another messageSource Bean already defined, but i wondered where it did come from. So i investigated further and found the following log output:

AnnotationConfigEmbeddedWebApplicationContext : Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@60df7989]

In fact it comes from the class AbstractApplicationContext in method initMessageSource (around line 622). There it checks for a bean with name "messageSource" and if it doesn't find one, it creates the above mentioned DelegatingMessageSource.

Am I missing something? Do I have to do something to get the MessageSourceAutoConfiguration happen before this AbstractApplicationContext stuff? Or is this really a bug?

For myself I fixed it by simply creating the messageSource myself as a @Bean, but using the AutoConfiguration would be far smarter :)

Greetings Christian

Felix
  • 5,452
  • 12
  • 68
  • 163
Koizumi
  • 185
  • 1
  • 12
  • I see this same issue still when using Spring Cloud, having some trouble figuring out what's causing it. Did you ever find out more info? – nerdherd Jul 24 '15 at 17:27
  • Just to be clear - MessageSourceAutoConfiguration works fine when you're using Spring Boot without Spring Cloud, so it seems to be a bug or limitation related to the initialization of one of the cloud components, maybe the configuration server? – nerdherd Jul 24 '15 at 17:34

1 Answers1

1

Turns out this is a bug, hopefully it gets resolved soon, tracked here:

https://github.com/spring-cloud/spring-cloud-commons/issues/29

nerdherd
  • 2,508
  • 2
  • 24
  • 40