I have achieved using AspectJ to add @Transactional to non-Bean class and non-public methods. However, I still can't make self-invocation success.
This is my transcation manager config class
@Configuration
@EnableTransactionManagement
public class DBConfig {
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager() {
DataSourceTransactionManager txManager = new DataSourceTransactionManager(DATA_SOURCE);
AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager);
return txManager;
}
}
This is my loadtime weaver config
@Configuration
@EnableLoadTimeWeaving
public class AspectJConfig implements LoadTimeWeavingConfigurer {
@Override
public LoadTimeWeaver getLoadTimeWeaver() {
return new InstrumentationLoadTimeWeaver();
}
}
And this is my self-invocation codes
public class Test {
@Transactional
public void testA() {
testB();
//......
}
@Transactional(propagation = Propagation.NEVER)
public void testB() {
//......
}
}
When I call testA, It's expected that it will throw exception because I have defined the propagation as NEVER. However, actually nothing happened.
So would anyone help me???