i used Preferences to store those properties
Code:
<aop:config proxy-target-class="true">
<aop:pointcut id="jmx.export.attribute" expression="execution(* set*(java.lang.String)) and @annotation(org.springframework.jmx.export.annotation.ManagedAttribute)"/>
<aop:advisor advice-ref="jmx.prefs.advice" pointcut-ref="jmx.export.attribute"/>
</aop:config>
<bean id="jmx.prefs.advice" class="wims.cycle.prefs.PreferencesPersisterAdvice"
p:userTreePath="wims.cycle"
/>
with an AfterReturningAdvice
Code:
public class PreferencesPersisterAdvice implements AfterReturningAdvice{
private String userTreePath;
private Preferences userPrefs;
Log logger = LogFactory.getLog(getClass());
public void afterReturning(Object returnValue, Method method,
Object[] args, Object target) throws Throwable {
logger.info(method);
try{
userPrefs.node(pathName(target)).put(key(method), value(args));
}catch(Exception e){
e.printStackTrace();
}
}
public void setUserTreePath(String userTreePath) {
this.userTreePath = userTreePath;
}
String pathName(Object target){
return target.getClass().getName();
}
String key(Method method){
return StringUtils.uncapitalize(StringUtils.delete(method.getName(), "set"));
}
String value(Object[] args){
if(args !=null && args.length==1 && args[0]!= null)
return args[0].toString();
throw new IllegalArgumentException();
}
@PostConstruct
void postConstruct(){
this.userPrefs = (this.userTreePath != null) ?
Preferences.userRoot().node(this.userTreePath) : Preferences.userRoot();
}
now how to read them back is already provided in Spring :
Code:
<bean id="prefs.config" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"
p:userTreePath="wims.cycle" p:properties-ref="prefs.props"
/>
<util:properties id="prefs.props">
<prop key="wims.cycle.rss.RssReader/sourceAddress">http://newsrss.bbc.co.uk/rss/sportonline_world_edition/other_sports/cycling/rss.xml</prop>
</util:properties>
convention between configurer and advice is to use the full class name as node