Web Serviceではspring beanを動的に取得します.
Web Serviceは起動時にspringをロードします.この時springはすべてのbeanの実用化を完成しました.
しかし、いくつかの項目の特殊性のため、一部のクラスはspringを通じて実用化する必要がなく、単にspring中のbean注入が必要です.この時はツールクラスSpringUtil.javaを書くことができます.
しかし、いくつかの項目の特殊性のため、一部のクラスはspringを通じて実用化する必要がなく、単にspring中のbean注入が必要です.この時はツールクラスSpringUtil.javaを書くことができます.
public class SpringUtil implements ApplicationContextAware {
private static ApplicationContext context;
public void setApplicationContext(ApplicationContext context)
throws BeansException {
SpringUtil.context = context;
}
public static Object getBean(String beanName) {
return context.getBean(beanName);
}
}
spring beanを注入する場合はSprigUtil.getBenを直接呼び出すだけでいいです.