In my Spring Boot project I have implemented following service method:
@Transactional
public boolean validateBoard(Board board) {
boolean result = false;
Your problem is a method's call from another method inside the same proxy.It's self-invocation. In your case, you can easily fix it without moving a method inside another service (why do you need to create another service just for moving some method from one service to another just for avoid self-invocation?), just to call the second method not directly from current class, but from spring container. In this case you call proxy second method with transaction not with self-invocatio.
This principle is useful for any proxy-object when you need self-invocation, not only a transactional proxy.
@Service
class SomeService ..... {
-->> @Autorired
-->> private ApplicationContext context;
-->> //or with implementing ApplicationContextAware
@Transactional(any propagation , it's not important in this case)
public boolean methodOne(SomeObject object) {
.......
-->> here you get a proxy from context and call a method from this proxy
-->>context.getBean(SomeService.class).
methodTwo(object);
......
}
@Transactional(any propagation , it's not important in this case)public boolean
methodTwo(SomeObject object) {
.......
}
}
when you do call context.getBean(SomeService.class).methodTwo(object);
container returns proxy object and on this proxy you can call methodTwo(...)
with transaction.