Jax-ws、spring 和 SpringBeanAutowiringSupport
虽然在我的@Webservice类中 我扩展了 SpringBeanAutowiringSupport,自动装配根本不适用于 Spring 2.5, 汤姆猫6。
没有注入任何东西。
我在主方法中测试了这些 bean 自动装配,使用 classpathcontext,一切都注入得很好。 但不适用于 jax-ws 端点。
你有想法吗?
although in my @Webservice class
I extend SpringBeanAutowiringSupport, autowiring simply does not work for Spring 2.5,
tomcat6.
nothing is injected.
I tested those beans autowiring in main method, using classpathcontext, everything is injected fine.
But not for jax-ws endpoint.
do you have ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我找到了解决方案。问题是 Spring 不会为
@WebService
类自动装配 bean(正如在其他论坛上发现的那样,这可能是当前的错误)。解决方案:
使用
org.springframework.beans.factory.config.AutowireCapableBeanFactory.class
而不是使用@Autowired
注释来注入你的bean(例如@Service
、@Repository
等)。所以:
包含
@Resource
WebServiceContext
<前><代码>@Resource
私有WebServiceContext上下文;
用它来获取你的bean
MyDAO
类可以如下所示:<前><代码>@Service
@Qualifier(“myDAO”)
@事务性
公共类 MyDAO {
私有 HibernateTemplate hibernateTemplate;
@必需的
@Autowired
公共无效setSessionFactory(SessionFactory sessionFactory){
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
公共MyInfo getMyInfo(长id){
返回 this.hibernateTemplate.get(MyInfo.class, id);
}
//...
}
在此之后,您可以在
中使用
方法。myDAO
对象@WebMethodI've found the solution. The problem is that Spring doesn't autowire beans for
@WebService
classes (as found on other forums it might be a current bug).The solution:
Use
org.springframework.beans.factory.config.AutowireCapableBeanFactory.class
instead of using@Autowired
annotation for injecting your beans (e.g.@Service
,@Repository
etc).So:
include
@Resource
WebServiceContext
use it for getting your bean
MyDAO
class can be as follows:after this you can use
myDAO
object in the@WebMethod
method.不知道大家的情况是不是一样。它通过更改 web.xml 中侦听器的顺序对我有用。将 ContextLoaderListener 放在 WSServletContextListener 之前解决了该问题。
I don't know if it's the same case as everyone else. It worked for me by changing the order of the listeners in web.xml. Putting the ContextLoaderListener before WSServletContextListener resolved the issue.
我猜您正在使用此配置元素:
但要启用对 @Endpoint 注释的支持,您必须添加此元素:
I'm guessing that you're using this config element:
But to enable support for the @Endpoint annotation, you must add this element:
如果您使用一些参考实现(例如 Metro、Axis2、apache-cxf)来轻松配置 Web 服务上的此类端点,那就更好了。
It would be better if you used some reference implementation, like Metro, Axis2, apache-cxf for easy configuration of such endpoint on web service.