@Transaction with @Service in spring annotation configuration
The problem is likely that your @Transactional
annotated class is situated in the servlet context. This may happen if you have <context:component-scan>
in your servlet application context configuration, while Spring AOP interceptors are configured in the root application context.
The solution is to move @Service
annotated classes to the root web app application context.
See Spring @Transactional not working.
The difference between Servlet and Web App Root context: Difference between applicationContext.xml and spring-servlet.xml in Spring Framework.
Alexander Camperov
Updated on June 04, 2022Comments
-
Alexander Camperov almost 2 years
I just cannot understand. Are beans marked with @Serviced and registered in application context by @ComponentScan proxied for transaction support via @Transaction annotation?
This works fine:
public class LocationManagerImpl implements LocationManager { @Transactional public void saveLocation(Location location) { } } //config class @Bean public LocationManager locationManager() { return new LocationManagerImpl(); }
and this doesn't:
@Service public class LocationManagerImpl implements LocationManager { @Transactional public void saveLocation(Location location) { } }