我有问题或者我在Spring Boot中发现了一个错误 . 我现在不确定 . 我有一个具有以下依赖项的项目
-
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
我想在我的Thymeleaf模板中使用messageSource,所以我在application.yml中设置了以下内容:
spring:
messages:
basename: de/mycompany/messages/message
并在上面的包中放置了message.properties和message_de.properties . 但替换不起作用 . 所以我调试了MessageSourceAutoConfiguration,发现@Conditional(ResourceBundleCondition.class)确实有效 . 它找到了我的资源并返回true . 所以我打印调试报告并发现,它说
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)
所以还有另一个messageSource Bean已经定义,但我想知道它来自哪里 . 所以我进一步调查,发现以下日志输出:
AnnotationConfigEmbeddedWebApplicationContext : Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@60df7989]
实际上,它来自方法initMessageSource中的类AbstractApplicationContext(第622行) . 在那里它检查名为“messageSource”的bean,如果找不到,则创建上面提到的DelegatingMessageSource .
我错过了什么吗?在AbstractApplicationContext之前,我是否必须做一些事情来获取MessageSourceAutoConfiguration?或者这真的是一个错误吗?
对于我自己,我通过简单地创建自己作为@Bean的messageSource来修复它,但使用AutoConfiguration会更聪明:)
问候基督徒
1 回答
事实证明这是一个错误,希望很快得到解决,在这里跟踪:
https://github.com/spring-cloud/spring-cloud-commons/issues/29