[英]One Apache Tomcat application server with 2 configured war applications and a MessageSource exception
I have an Apache Tomcat application server, version 8.5.30, and it has 2 web applications configured on it. 我有一个Apache Tomcat应用程序服务器,版本为8.5.30,并且在其上配置了2个Web应用程序。
These applications have Spring Framework 5 and each one has its own ReloadableResourceBundleMessageSource because I use internationalization of messages (i18n). 这些应用程序具有Spring Framework 5,并且每个应用程序都有其自己的ReloadableResourceBundleMessageSource,因为我使用消息的国际化(i18n)。
When I start Apache and load one of the sites, the site that was opened first has its messages loaded into memory, and the second site when I open doesn't have its messages loaded. 当我启动Apache并加载一个站点时,第一个打开的站点将其消息加载到内存中,而当我打开的第二个站点未加载其消息。 So this causes an exception message on second application and throws an exception like:
因此,这会在第二个应用程序上导致异常消息,并引发如下异常:
Caused by: org.springframework.context.NoSuchMessageException : No message found under code 'menu.login' for locale 'en_US'.
原因:org.springframework.context.NoSuchMessageException:在代码“ menu.login”下找不到区域设置“ en_US”的消息。
To try to solve this problem, I tried to create two different MessagesSources, one for each application, but when loading the application server another exception was thrown: 为了尝试解决此问题,我尝试创建两个不同的MessagesSources,每个应用程序一个,但是在加载应用程序服务器时引发了另一个异常:
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.context.MessageSource] is defined: expected single matching bean but found 2: messageSourceA, messageSourceB.
由以下原因引起:org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义类型为[org.springframework.context.MessageSource]的合格bean:期望的单个匹配bean,但找到2:messageSourceA,messageSourceB。
Some example about how I tried to do 关于我如何尝试做的一些例子
AppA in ROOT.war (alias 1) ROOT.war中的AppA(别名1)
@Bean
public MessageSource messageSourceA() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath*:messageA", "classpath*:enumaratorA");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
AppB in ROOT.war (alias 2) ROOT.war中的AppB(别名2)
@Bean
public MessageSource messageSourceB() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath*:messageB", "classpath*:enumaratorB");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
Please, could you help me to solve this problem? 拜托,您能帮我解决这个问题吗?
How can I make the Apache/Spring understand that they are two different sources? 如何使Apache / Spring理解它们是两个不同的来源?
What other options can be made? 还有什么其他选择?
Thanks in advance. 提前致谢。
I would suggest to try for this to work. 我建议尝试使其工作。
Assuming properties files are stored at project's src/main/resources
package. 假设属性文件存储在项目的
src/main/resources
包中。 Please remove file suffix .properties
so that only messageB
and enumeratorB
remains in messageSource.setBasenames("classpath:messageB", "classpath:enumaratorB");
请删除文件后缀
.properties
以便在messageSource.setBasenames("classpath:messageB", "classpath:enumaratorB");
中仅messageB
和enumeratorB
messageSource.setBasenames("classpath:messageB", "classpath:enumaratorB");
and double check file path and spelling. 并仔细检查文件路径和拼写。
If your properties files are in classpath, please use classpath*:
otherwise Spring will look for properties in web directory of your application. 如果您的属性文件在classpath中,请使用
classpath*:
否则Spring将在您的应用程序的Web目录中查找属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.