实施Grails服务时存在继承问题 [英] Issues with inheritance when implementing Grails services
问题描述
@Transactional
public class MammalService {
public mammalMethod(){
}
}
@Transactional
public class DogService扩展MammalService {
public dogMethod(){
mammmalMethod()
}
}
当从特定的方法调用继承的方法时, 有没有人在服务中使用过这种方法?我错过了什么? PS:奇怪的是,我试着改变 UPDATE1:在调试时,我可以看到TWO在我的专门服务中有同名TransactionManager的变量(检查具体超类时不会发生的事情)。 p> 我在在Grails服务中重复的transactionManager属性 通过从@Transaction中移除专门的服务类和 看来,对于专门的服务类,事务例程尝试重新注入 So, is it not recommended using an inheritance-approach when implementing Grails services? I went through a simple service specialization pattern understanding that all would work in a transparent way, but I started to go into trouble regarding transaction management under the spring/grails hood. Issues happen when a method from the specialized class calls a method from the inherited class (both concrete services themselves): It comes that when the inherited method is called from the specialized one, Has anyone used such approach with services? Am I missing something? PS: Curiously, I tried changing the UPDATE1: While debugging, I can see TWO variables with the same name transactionManager inside my specialized service (something that doesn't happen when inspecting the concrete superclass). I'm opening a more specific issue at Duplicated transactionManager property in Grails service Solved by removing @Transaction from specialized service classes and
methods, keeping them only on the inherited service class and its methods.
It seems that, for specialized service classes, the transaction routines try to re-inject the 这篇关于实施Grails服务时存在继承问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! org.springframework.transaction.support.GrailsTransactionTemplate() code>构造函数被一个null
transactionManager
参数触发(通过spring / grails事务AOP),这会导致一些 NullPointerException
另外。
@ grails.transaction.Transactional
注释 @ org.springframework.transaction.annotation.Transactional
和 NullPointerException
停止发生。 (尽管如此,它并没有指出一个很好的解决方案,因为其他副作用开始发生在我的池管理中)。
方法,只保留它们继承的服务类和方法。
@Transactional
public class MammalService {
@Transactional(readonly = true)
public mammalMethod(){
}
}
//不用@Transactional注释 - 依赖于超类声明
public class DogService扩展MammalService {
//不用@Transactional注释 - 依靠超类事务声明
public dogMethod(){
mammmalMethod()
}
}
transactionManager
属性,导致两个具有相同名称并且其中一个为空的属性。另外,注释覆盖方法会引发StackOverflowException。@Transactional
public class MammalService {
public mammalMethod() {
}
}
@Transactional
public class DogService extends MammalService {
public dogMethod() {
mammmalMethod()
}
}
org.springframework.transaction.support.GrailsTransactionTemplate()
constructor is fired (by the spring/grails transaction AOP) with a null transactionManager
argument, which causes some NullPointerException
moreover.@grails.transaction.Transactional
annotation by the @org.springframework.transaction.annotation.Transactional
and the NullPointerException
ceased from happening. (Nevertheless, it didn't point to a nice solution, since other side effects started to happen with my pool management).
@Transactional
public class MammalService {
@Transactional(readonly=true)
public mammalMethod() {
}
}
//Don't annotate with @Transactional - rely on the super class declaration
public class DogService extends MammalService {
//Don't annotate with @Transactional - rely on the super class transactional declaration
public dogMethod() {
mammmalMethod()
}
}
transactionManager
attribute, resulting in two attributes with the same name and one of them null. Also, annotating overrided methods raises an StackOverflowException.