虽然在我的@Webservice类中
我扩展了 SpringBeanAutowiringSupport,自动装配根本不适用于 Spring 2.5,
汤姆猫6。
没有注入任何东西。
我在主方法中测试了这些 bean 自动装配,使用 classpathcontext,一切都注入得很好。
但不适用于 jax-ws 端点。
你有想法吗?
我找到了解决方案。问题是 Spring 不会自动装配 bean@WebService
类(如在其他论坛上发现的那样,这可能是当前的错误)。
解决方案:
Use org.springframework.beans.factory.config.AutowireCapableBeanFactory.class
而不是使用@Autowired
用于注入 Bean 的注释(例如@Service
, @Repository
etc).
So:
-
include @Resource
WebServiceContext
@Resource
private WebServiceContext context;
-
用它来获取你的豆子
MyDAO myDAO = null;
ServletContext servletContext = (ServletContext) context
.getMessageContext().get("javax.xml.ws.servlet.context");
WebApplicationContext webApplicationContext = WebApplicationContextUtils
.getRequiredWebApplicationContext(servletContext);
myDAO = (MyDAO) webApplicationContext
.getAutowireCapableBeanFactory().getBean("myDAO");
MyDAO
类可以如下:
@Service
@Qualifier("myDAO")
@Transactional
public class MyDAO {
private HibernateTemplate hibernateTemplate;
@Required
@Autowired
public void setSessionFactory(SessionFactory sessionFactory) {
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
public MyInfo getMyInfo(Long id){
return this.hibernateTemplate.get(MyInfo.class, id);
}
//...
}
之后你可以使用myDAO
对象在@WebMethod
method.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)