Spring Boot MessageSourceAutoConfiguration

小泉

我有问题,或者可能我在Spring Boot中发现了一个错误。我目前不确定。我有一个具有以下依赖项的项目

  • 弹簧启动启动器百里香
  • 弹簧启动启动器网络
  • 弹簧启动启动器执行器
  • spring-boot-starter-mail
  • 弹簧云启动总线amqp
  • 弹簧云启动器配置
  • 春天云启动器尤里卡

我想在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。

我想念什么吗?我是否需要做一些事情才能使MessageSourceAutoConfiguration在AbstractApplicationContext之类的东西之前发生?还是这真的是一个错误?

对于我自己,我可以通过将自己的messageSource本身创建为@Bean来解决它,但是使用AutoConfiguration会更聪明:)

问候基督徒

一群书呆子

原来这是一个错误,希望可以尽快解决,请在此处进行跟踪:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章