당신은 자동으로 종속성을 등록 할 BeanFactoryPostProcessor 인터페이스를 구현하는 클래스를 작성 시도 할 수 :
경고 :이 클래스는 컴파일되지 않았습니다.
public class DatabaseMigratorDependencyResolver implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
String[] beanNames = beanFactory.getBeanDefinitionNames();
for (String beanName : beanNames) {
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
// Your job is here:
// Feel free to make use of the methods available from the BeanDefinition class (http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/BeanDefinition.html)
boolean isDependentOnDatabaseMigrator = ...;
if (isDependentOnDatabaseMigrator) {
beanFactory.registerDependentBean("databaseMigrator", beanName);
}
}
}
}
그런 다음이 클래스의 빈을 다른 모든 빈과 함께 포함 할 수 있습니다.
<bean class="DatabaseMigratorDependencyResolver"/>
스프링은 나머지 빈 시작을 시작하기 전에 자동으로 실행됩니다.
감사합니다. –
아무도 내 솔루션이 마음에 들지 않으므로 답변을 선택하겠습니다. 감사! –