I have a single configuration bean that has the app's configuration settings. I want to expose this bean to any java class in my application. Do i autowire it to every class that need the bean or do i set it to a static field in some global class to make it conveniently accessible to every class? Is autowiring reasonable/recommended for high turnover objects? In my case this would be some network events coming in multiples every second.
问问题
323 次
1 回答
0
我在 AspectJ 编译时(或加载时)编织中使用了这种方法:
public final class Config {
public static String oneParticularSetting() {
return new ConfigHolder().oneParticularSetting;
}
@Configurable
private static class ConfigHolder {
@Value("${oneParticularSetting}")
private String oneParticularSetting;
}
}
自动装配开销/性能是您只需要测试的东西。
或者您可以重用 ConfigHolder 实例(考虑线程安全)。
于 2013-05-29T20:18:42.933 回答