Q:

Spring 4 @Transactional doesn't work

I have a Spring 4.3 Application with simple configuration and I expect my methods from service classes to be transactional so I enable transaction management in my configuration and then annotate my service methods with @Transactional. I call service methods from my controlles but they don't behave as expected. When some part of a method throws exception rollback is never called
AppInitializer.class:
@EnableTransactionManagement
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{WebConfig.class};
    }
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[]{RootConfig.class, SecurityConfig.class};
    }
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}

RootConfig.class:
@Configuration
@EnableJpaRepositories(basePackages"package.repository"})
public class RootConfig {
    @Bean
    public DataSource dataSource() {
        ...
        return dataSource;
    }
    @Bean
    public JpaVendorAdapter jpaVendorAdapter() {
        ...
        return hibernateJpaVendorAdapter;
    }
    @Bean
    public EntityManagerFactory entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        ...
        return factory.getObject();
    }
    @Bean
    public JpaTransactionManager transactionManager() {
        return new JpaTransactionManager(entityManagerFactory());
    }
}

Does anybody have idea what is wrong here
GitHub link https://github.com/VadOs1/TRANSACTIONAL-ISSUE/
Thanks

A:

can you remove the @EnableTransactionManagement annotation from the AppInitializer class and enable it in RootConfig class and let me know if this worked for you
ie
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages"package.repository"})
public class RootConfig {
    @Bean
    public DataSource dataSource() {
        ...
        return dataSource;
    }
    @Bean
    public JpaVendorAdapter jpaVendorAdapter() {
        ...
        return hibernateJpaVendorAdapter;
    }
    @Bean
    public EntityManagerFactory entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        ...
        return factory.getObject();
    }
    @Bean
    public JpaTransactionManager transactionManager() {
        return new JpaTransactionManager(entityManagerFactory());
    }
}

