简体   繁体   English

类似于Spring中针对非EJB的EJB连接

[英]Something like EJB wiring in Spring for non EJB's

I've noticed recently that spring can wire up my ejb's for me if I annotate the ejb with @Interceptors(SpringBeanAutowiringInterceptor.class). 我最近注意到,如果我使用@Interceptors(SpringBeanAutowiringInterceptor.class)注释ejb,那么spring可以为我连接我的ejb。 I've never actually done this so don't know the details. 我从来没有真正这样做过,所以不知道细节。

I was wondering, is there a way to get this to work with other kinds of beans, for example, @WebService annotated ones as well. 我想知道,有没有办法让它与其他类型的bean一起工​​作,例如@WebService注释的bean。

At the moment in my web service classes (because the application server manages them) I have to load the dependencies from the BeanFactory and would thus prefer to have them autowired. 目前在我的Web服务类中(因为应用程序服务器管理它们)我必须从BeanFactory加载依赖项,因此更愿意让它们自动装配。

I know I could use the @Configurable annotation but am not particularly keen to have to specify and agent on the VM. 我知道我可以使用@Configurable注释但不是特别热衷于必须在VM上指定和代理。

Is this possible? 这可能吗?

Once again, spring has thought of this use case and catered for it! 春天再一次想到了这个用例并迎合了它!

The problem is that @WebService is not a spring annotation, it is a JAX-WS annotation and thus classes that are annotated with @WebService to be exposed as web services are not managed by spring, but their life cycle is managed by JAX-WS. 问题是@WebService不是一个spring注释,它是一个JAX-WS注释,因此用@WebService注释作为Web服务公开的类不是由spring管理的,但它们的生命周期由JAX-WS管理。

The way to handle this case is to have the JAX-WS managed bean extend org.springframework.web.context.support.SpringBeanAutowiringSupport - this will enable the @Autowire annotation, for example, to work in this bean. 处理这种情况的方法是让JAX-WS托管bean扩展org.springframework.web.context.support.SpringBeanAutowiringSupport - 这将启用@Autowire注释,例如,在此bean中工作。 see here for more information 请看这里了解更多信息

Yes, of course. 当然是。 There's @WebService, @Repository, @Controller, @Service, @Endpoint, and other annotations in Spring. Spring中有@ WebService,@ Repository,@ Controller,@ Service,@ Endpoint和其他注释。 Here's an example . 这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM