Migrate from Struts 2.3.33 to Struts 2.5.12 LocalizedTextUtil is removed(从 Struts 2.3.33 迁移到 Struts 2.5.12 LocalizedTextUtil 被移除)
问题描述
我们尝试从 Struts 2.33 迁移到 Struts 2.5.12.
We tried to migrate from Struts 2.33 to Struts 2.5.12.
我们在应用程序中直接使用了LocalizedTextUtil
.
We used LocalizedTextUtil
in our application directly.
我发现 LocalizedTextUtil
已从 com.opensymphony.xwork2.util.LocalizedTextUtil
中删除.我试图搜索但找不到任何东西
I found that the LocalizedTextUtil
is removed from com.opensymphony.xwork2.util.LocalizedTextUtil
. I tried to search but could not find any thing
我发现了一些类,如 StrutsLocalizedTextProvider
和 GlobalLocalizedTextProvider
但似乎它们不是我可以使用的.
I found some classes like StrutsLocalizedTextProvider
and GlobalLocalizedTextProvider
but it seems they are not what I can use them.
我已查看 migration-guide,但找不到任何关于它.
I have reviewed migration-guide but could not find any comment about it.
有什么选择?
推荐答案
struts.xml应该设置为:
The struts.xml should be set as:
<constant name="struts.xworkTextProvider" value="DefaultTextProvider" />
<bean type="com.opensymphony.xwork2.TextProvider" name="DefaultTextProvider" class="utils.CustomTextProvider" scope="default" />
并且 CustomStrutsTextProviderFactory
可以添加捆绑包
And CustomStrutsTextProviderFactory
could add bundles
public class MyTextProviderFactory implements TextProviderFactory {
protected LocaleProviderFactory localeProviderFactory;
protected LocalizedTextProvider localizedTextProvider;
@Inject
public MyTextProviderFactory(LocaleProviderFactory localeProviderFactory, LocalizedTextProvider localizedTextProvider) {
this.localeProviderFactory = localeProviderFactory;
this.localizedTextProvider = localizedTextProvider;
this.localizedTextProvider.addDefaultResourceBundle("messages/label");
this.localizedTextProvider.addDefaultResourceBundle("messages/customerA/label");
}
@Override
public TextProvider createInstance(Class clazz) {
TextProvider instance = getTextProvider(clazz);
if (instance instanceof ResourceBundleTextProvider) {
((ResourceBundleTextProvider) instance).setClazz(clazz);
((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
}
return instance;
}
@Override
public TextProvider createInstance(ResourceBundle bundle) {
TextProvider instance = getTextProvider(bundle);
if (instance instanceof ResourceBundleTextProvider) {
((ResourceBundleTextProvider) instance).setBundle(bundle);
((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
}
return instance;
}
protected TextProvider getTextProvider(Class clazz) {
return new TextProviderSupport(clazz, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
}
protected TextProvider getTextProvider(ResourceBundle bundle) {
return new TextProviderSupport(bundle, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
}
}
完整归功于@LukazLenart https://issues.apache.org/jira/浏览/WW-4829
Complete credits to @LukazLenart https://issues.apache.org/jira/browse/WW-4829
这篇关于从 Struts 2.3.33 迁移到 Struts 2.5.12 LocalizedTextUtil 被移除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Struts 2.3.33 迁移到 Struts 2.5.12 LocalizedTextUtil 被移除


基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01