3

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) {

    }

}
Alexander Camperov
  • 393
  • 2
  • 5
  • 11

1 Answers1

3

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.

Community
  • 1
  • 1
Boris Treukhov
  • 17,493
  • 9
  • 70
  • 91