I have a question:
Why when we annotate method with @Scheduled
and @Transaction
, transaction doesn't work?
I know that the @Scheduled
call my class instead of proxy class that created by Spring, but can't understand this behavior.
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
@Service
public class UserServiceImpl implements UserService {
@Override
@Scheduled(fixedRateString = "${somestring}",initialDelayString = "${anotherstring}")
@Transactional
public void doSomething() {
}
}
I have two solutions of this problem:
Call proxy from
Scheduled
method.Implement
ConcurrentTaskScheduler
and replace object ofScheduledMethodRunnable
(that is with my class) with object ofScheduledMethodRunnable
with proxy.
But this solutions is very inconvenient.
Can you explaim me why @Scheduled
works like this?
Thank you!