开发者

Will a transactional annotated method overridden in a sub-interface still start a transaction

Consider this scenario for a Java application with Spring:

开发者_开发知识库
public interface FooDao {
    @Transactional
    void save(Foo foo);
}

public interface SecureFooDao extends FooDao {
    @Secured({Role.ADMIN})
    void save(Foo foo);
}

My question is this; will calling save on a SecureFooDao interface start a transaction, or will it ignore the overriden methods annotations?


From Spring reference 10.5.6 Using @Transactional

Tip

Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the @Transactional annotation, as opposed to annotating interfaces. You certainly can place the @Transactional annotation on an interface (or an interface method), but this works only as you would expect it to if you are using interface-based proxies. The fact that Java annotations are not inherited from interfaces means that if you are using class-based proxies (proxy-target-class="true") or the weaving-based aspect (mode="aspectj"), then the transaction settings are not recognized by the proxying and weaving infrastructure, and the object will not be wrapped in a transactional proxy, which would be decidedly bad.

So even not overriden it will only work if you use Spring-Aop-Proxies (which I can not recommend), but not for AspectJ or CGILib Proxies!

But I do not expect that this work for an method that is overriden in an Interface, even not for Spring-Aop-Proxies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜