[英]Tomcat JDBC configured on Server and included in Application WAR
[英]One Apache Tomcat application server with 2 configured war applications and a MessageSource exception
我有一个Apache Tomcat应用程序服务器,版本为8.5.30,并且在其上配置了2个Web应用程序。
这些应用程序具有Spring Framework 5,并且每个应用程序都有其自己的ReloadableResourceBundleMessageSource,因为我使用消息的国际化(i18n)。
当我启动Apache并加载一个站点时,第一个打开的站点将其消息加载到内存中,而当我打开的第二个站点未加载其消息。 因此,这会在第二个应用程序上导致异常消息,并引发如下异常:
原因:org.springframework.context.NoSuchMessageException:在代码“ menu.login”下找不到区域设置“ en_US”的消息。
为了尝试解决此问题,我尝试创建两个不同的MessagesSources,每个应用程序一个,但是在加载应用程序服务器时引发了另一个异常:
由以下原因引起:org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义类型为[org.springframework.context.MessageSource]的合格bean:期望的单个匹配bean,但找到2:messageSourceA,messageSourceB。
关于我如何尝试做的一些例子
ROOT.war中的AppA(别名1)
@Bean
public MessageSource messageSourceA() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath*:messageA", "classpath*:enumaratorA");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
ROOT.war中的AppB(别名2)
@Bean
public MessageSource messageSourceB() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath*:messageB", "classpath*:enumaratorB");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
拜托,您能帮我解决这个问题吗?
如何使Apache / Spring理解它们是两个不同的来源?
还有什么其他选择?
提前致谢。
我建议尝试使其工作。
假设属性文件存储在项目的src/main/resources
包中。 请删除文件后缀.properties
以便在messageSource.setBasenames("classpath:messageB", "classpath:enumaratorB");
中仅messageB
和enumeratorB
messageSource.setBasenames("classpath:messageB", "classpath:enumaratorB");
并仔细检查文件路径和拼写。
如果您的属性文件在classpath中,请使用classpath*:
否则Spring将在您的应用程序的Web目录中查找属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.