简体   繁体   English

一台Apache Tomcat应用程序服务器,具有2个配置的war应用程序和一个MessageSource异常

[英]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");中仅messageBenumeratorB 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.

相关问题 Tomcat JDBC 在服务器上配置并包含在应用程序 WAR 中 - Tomcat JDBC configured on Server and included in Application WAR Apache服务器RewriteRule与Tomcat战争-从URL删除应用程序名称 - Apache server RewriteRule to Tomcat war - Remove application name from url 无法在Apache Tomcat服务器上启动Spring Boot应用程序(WAR文件) - Spring Boot Application(WAR file) could not be started On Apache Tomcat Server 在 tomcat 服务器上部署 a.war 应用程序 - Deploying a .war application on a tomcat server 在Apache Tomcat上运行针对不同IDP配置的多个Fedlet应用程序 - Running multiple Fedlet applications configured against different IDPs on Apache Tomcat Apache web server or Tomcat for java war and php - Apache web server or Tomcat for java war and php 如何在tomcat服务器中管理多个war应用程序? - how to manage multiple war application in tomcat server? 一次将Web应用程序部署到Apache Http Server和Tomcat - Deploy Web Application to Apache Http Server and Tomcat in one go 如何对在Apache Tomcat上运行的War应用程序使用版本控制 - How to use versioning for a war application running on Apache Tomcat 使用 Tomcat 配置 Apache Web 服务器并尝试部署战争文件 - Configure Apache Web Server with Tomcat and trying to Deploy war file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM