我想在推土机映射文件中访问我的环境变量。有办法吗?我查看了官方文档,他们列出了变量的用法。但它们不是环境变量。还有一种方法可以访问推土机映射文件中的 .property 文件值吗?
问问题
204 次
1 回答
0
最简单的方法是使用类工厂并创建该类的新实例并传入所需的环境变量。请参阅文档。http://dozer.sourceforge.net/documentation/custombeanfactories.html
public class EnvironmentSetterBeanFactory implements BeanFactory {
public Object createBean(Object source, Class<?> sourceClass, String targetBeanId) {
try {
Class<?> targetClass;
targetClass = Class.forName(targetBeanId);
Object instance = targetClass.newInstance()
if (instance instanceof YourClass) {
YourClass yourClass = (YourClass) idSource;
yourClass.setThatVar(System.getenv("myenvvar"));
}
return instance;
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
于 2012-06-15T15:46:25.010 回答