我有一个库进行运行时设置和log4j的配置(没有log4j.properties或log4j.xml).我已经使用名为MyLoggerFactory的类定义了一个bean,我希望这是第一个使用spring初始化的bean.我看到的问题已与春季提交到有初始化的订单支持,但我不知道是否有标记一个bean作为第一个bean由Spring容器被初始化的方法吗?
mil*_*ose 42
你的选择是:
@DependsOn注释(在spring 3.0.x之后可用)或depends-onxml-attribute并使所有使用配置的记录器的类依赖于记录器工厂main()方法,或者ServletContextListener在初始化Spring之前注册的方法.有没有办法在春季明确定义初始化顺序和可能永远不会 - 有没有办法来定义它有用的语义考虑您可以加载可能有冲突的排序许多应用程序上下文配置文件.我还没有看到通过重构代码以更好地符合依赖注入模式而无法实现所需顺序的情况.
bla*_*lle 12
您可以@Autowired @Configuration中的@Configuration
@Configuration
@Import(BusinessConfig.class, EarlyBeans.class)
public class MainConfiguration {
// The bean defined in EarlyBean will be loaded before
// most beans references by MainConfiguration,
// including those coming from BusinessConfig
@Autowired
EarlyBean earlyBean;
}
@Configuration
public class EarlyBeans {
@Bean
public Void earlyBean(ApplicationContext appContext) {
// .getBeansOfType allows to call for beans which might not exist
appContext.getBeansOfType(TechnicalBean.class);
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
86201 次 |
| 最近记录: |