1
나는 자바 1.4와 봄 2.5를 사용하여 프로젝트가있다. 일부 서비스를 제공하는 타사 라이브러리를 사용합니다. name
서비스의 인터페이스의 이름이며, 방법은 구현을 반환봄 수동으로 콩을 추가하십시오
class XFactory {
Object getService(String name);
}
. 나는 봄 콩으로이 클래스를 확장하고 결과를 등록 할 :
class YFactory extends XFactory implements ApplicationContextAware {
private ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
Object getService(String name) {
Object service = super.getService(name);
registerBean(applicationContext, name, service);
return service;
}
}
어떻게 registerBean
을 구현하기 위해? 나는 인터넷 검색을했지만, n 번째가 작동되었습니다의 DefaultListableBeanFactory는 CCE의 원인에 appCtx 캐스팅, 내가의 FactoryBean에 XFactory을 변경하지 못할 (제 3 자)
추가 STH 같은 : '하고 ConfigurableBeanFactory CFB = (하고 ConfigurableBeanFactory) applicationContext.getAutowireCapableBeanFatory();' '경우 {' 'cfb.registerSingleton (intfName (cfb.containsBean (service.getName())!) 서비스); '}' 괜찮습니까?하지만 잘 작동하는지 확인하십시오. - appCtx.getBean (name)은 sth! = null을 반환하며 아직 완전히 테스트되지 않았습니다. 이제 다른 문제가 있습니다. 나는 Spring AOP를 사용한다. 그래서 원래의 서비스를 프록시 처리 할 수있다. 그래서 그것은 이미 aop.xml에 정의 된 모든 aspect를 포함하고 있는가? – alef
'잘 모르겠다' '코드가 이미 Spring API에 직접 의존하고 있으므로, 앞으로 Spring을 변경하면 그 부분이 중단 될 가능성이 있습니다. 이 움직임은 큰 차이를 만들지 않을 것입니다. Aop을 위해, 나는 코드를보고 대답을 찾을 수 없었다. – Adi