在Struts 2.3,覆蓋我們struts.xml中使用下面2.15 STRUST如何重寫TextProviderSupport定製資源bundel mesages
集豆的TextProvider
:
<bean type="com.opensymphony.xwork2.TextProvider" name="DefaultTextProvider" class="util.CustomTextProvider" scope="default" />
而且使CustomTextProvider
public class CustomTextProvider extends DefaultTextProvider{
public String getText(String key, String defaultValue, List<?> args) {
String text = super.getText(key, defaultValue, args);
//Do something with the text
//and return it
}
//other getText methods can be override too
}
這似乎不適用於Struts 2.15。 2。
當我放了一些斷點時,我的方法都沒有被調用,看起來我的bean沒有註冊。
我認爲StrutsLocalizedTextProvider
可能是一個被重寫。但似乎我無法定義一個擴展它的bean。 我得到這個錯誤:
Unable to load configuration. - bean - file:/E:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/WEB-INF/classes/struts.xml:12:156
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:960)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:466)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:499)
at org.apache.struts2.dispatcher.InitOperations.initDispatcher(InitOperations.java:75)
at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:63)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4590)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5233)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: Unable to load bean: type:com.opensymphony.xwork2.LocalizedTextProvider class:utils.CustomLocalizedTextProvider - bean - file:/E:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/WEB-INF/classes/struts.xml:12:156
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:271)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:98)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:164)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:63)
... 17 more
Caused by: Bean type interface com.opensymphony.xwork2.LocalizedTextProvider with the name struts has already been loaded by [unknown location] - bean - file:/E:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/WEB-INF/classes/struts.xml:12:156
能否請你讓我知道該如何處理呢?!
親愛的@RomanC你的答案似乎是完整的,我已經檢查http://struts.apache.org/maven/struts2-core/apidocs/com/opensymphon y/...,這證明了這種方式。但升級到2.5.12後它不起作用。爲了做一些測試,我從'strust.xml'中刪除了我的bean,並在'DefaultTextProvider'中放置了一些斷點,這個類的'getText'沒有被調用,但是我發現調用了'TextProviderSupport'' getText'方法。任何想法?我們應該重寫另一個課程嗎?! –
是的,閱讀提供給這個答案的鏈接。 –