【问题标题】:Disable multilingual option in Apache tiles 3在 Apache tile 3 中禁用多语言选项
【发布时间】:2017-02-06 00:28:32
【问题描述】:
我收到了 Apche tile 3 和 Spring MVC 4 的以下警告,我没有为多语言支持添加任何额外的配置,但默认情况下它支持。谁能帮我禁用此选项以在我的网站中删除此警告。
org.apache.tiles.request.locale.PostfixedApplicationResource.
<init> No supported matching language for locale "sw".
Using file:/opt/apache-tomcat-8.0.35/webapps/ROOT/WEB-INF/tiles/app-core_sw.xml as a non-localized resource path. see TILES-571
【问题讨论】:
标签:
spring-mvc
tomcat
apache-tiles
tiles-3
【解决方案1】:
您可以通过编写自己的 DefinitionFactory 实现并在 TilesConfigurer 中注册来禁用此选项。
public class CustomLocaleDefinitionsFactory extends LocaleDefinitionsFactory {
/** {@inheritDoc} */
@Override
public Definition getDefinition(String name, Request tilesContext) {
Definition retValue;
Locale locale = null;
retValue = definitionDao.getDefinition(name, locale);
if (retValue != null) {
retValue = new Definition(retValue);
String parentDefinitionName = retValue.getExtends();
while (parentDefinitionName != null) {
Definition parent = definitionDao.getDefinition(parentDefinitionName, locale);
if (parent == null) {
throw new NoSuchDefinitionException("Cannot find definition '" + parentDefinitionName
+ "' ancestor of '" + retValue.getName() + "'");
}
retValue.inherit(parent);
parentDefinitionName = parent.getExtends();
}
}
return retValue;
}
}
然后在TilesConfigurer中注册上面的定义因子类,以防像这样使用spring。
TilesConfigurer configurer = new TilesConfigurer();
configurer.setDefinitions(new String[] { "/WEB-INF/layouts/tiles.xml",
"/WEB-INF/views/**/tiles.xml" });
configurer.setCheckRefresh(true);
configurer.setDefinitionsFactoryClass(CustomLocaleDefinitionsFactory.class);
return configurer;
【解决方案2】:
有一个变通方法,只要禁用日志输出就可以了,如果你使用的是spring boot,很简单:
logging.level.org.apache.tiles.request.locale.PostfixedApplicationResource=ERROR