Spring + Jersey事务注释 [英] Spring+Jersey transactional annotation

查看:142
本文介绍了Spring + Jersey事务注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建了样板项目,以向启用JPA的数据库公开RESTful API.它使用以下版本:
-春季3.2.6
-休眠4.3.0
-泽西岛2.5.1
我终于能够让他们一起玩,但是仍然存在一些问题.这是最令人困惑的事情之一(请参阅REST服务类的摘录)

Created boilerplate project to expose RESTful API to JPA enabled database. It's using the following versions:
- Spring 3.2.6
- Hibernate 4.3.0
- Jersey 2.5.1
I finally was able to get them playing together, but still some question remains. Here's one of the most puzzling things (see excerpt from REST service class)

@Service
@Path("resources")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
@Transactional
public class ResourceServices extends AbstractServices<Resource> {
...
}

如果类使用@Service进行注释,则@Transactional注释将被忽略,并且不会启动方法的事务.但是,当更改为@Component时,一切正常.无法弄清楚,为什么.

if class is annotated with @Service, @Transactional annotation is ignored and transaction for the methods is not started. However, when changed to @Component, everything works fine. Couldn't figure out, why.

可以在此处

推荐答案

我也对此感到困惑,但最终发现了这一点.

I got puzzled by this as well, but finally figured this out.

jersey-spring模块将仅从您的上下文中导入@Component bean.从字面上看是beanClass.isAnnotationPresent(Component.class)签入SpringComponentProvider.

The jersey-spring module will only import @Component beans from your context. There literally is a beanClass.isAnnotationPresent(Component.class) check in SpringComponentProvider.

否则,它似乎仅创建半生的请求范围的Bean实例(我在服务构造函数中使用Thread.dumpStack进行了跟踪).他们似乎有依赖项注入,但没有AOP.

Otherwise it appears to only create half-baked request-scoped instances of the bean (I traced this with Thread.dumpStack in service constructor). They seem to have dependency injection, but not AOP.

泽西岛的问题跟踪器中已经有许多JIRA项目: JERSEY-2495 JERSEY-2059

There's a number of JIRA items already in Jersey's issue tracker: JERSEY-2495, JERSEY-2059, JERSEY-2301

更新:我对这些请求的合并请求已合并,应该在Jersey 2.11中修复.

UPDATE: My pull request for these has been merged, this should be fixed in Jersey 2.11.

这篇关于Spring + Jersey事务注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆