我知道有ServletContextPropertyPlaceholderConfigurer
:
将占位符解析为ServletContext init参数(即web.xml context-param条目)。
是否有人知道PropertyPlaceholderConfigurer
类似地将占位符解析为portlet-preferences
(即portlet.xml
portlet-preference
个条目?
答案 0 :(得分:4)
以下是我解决问题的方法,最后编写了一个类似于ServletContextPropertyPlaceholderConfigurer的类: - )
public class PortletConfigPropertyPlaceholderConfigurer extends
PropertyPlaceholderConfigurer implements PortletConfigAware {
private PortletConfig portletConfig;
private boolean configOverride = false;
public void setPortletConfig(PortletConfig portletConfig) {
this.portletConfig = portletConfig;
}
public void setConfigOverride(boolean configOverride) {
this.configOverride = configOverride;
}
@Override
protected String resolvePlaceholder(String placeholder, Properties props) {
String value = null;
if (this.configOverride && this.portletConfig != null) {
value = resolvePlaceholder(placeholder, this.portletConfig);
}
if (value == null) {
value = super.resolvePlaceholder(placeholder, props);
}
return value;
}
protected String resolvePlaceholder(String placeholder,
PortletConfig portletConfig) {
return portletConfig.getInitParameter(placeholder);
}
}
干杯, 格