When i try to use:
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
transaction not working, but if i use
@EnableTransactionManagement(mode = AdviceMode.PROXY)
everything works fine.
My code:
SpringBootAplication
@SpringBootApplication
@EnableScheduling
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
public class SpringBootAplication
{
private static ConfigurableApplicationContext applicationContext;
public static void main(String[] args)
{ System.out.println(InstrumentationLoadTimeWeaver.isInstrumentationAvailable());
applicationContext = SpringApplication.run(SpringBootAplication.class, args);
}
Controller
@RestController
public class MyController
{
@Autowired
MyRepository repository;
@Transactional
@RequestMapping(value = "/", method = RequestMethod.GET)
public void test()
{
repository.findById("name");
System.out.println(TransactionAspectSupport.currentTransactionStatus());
}
}
Also i have a VM options: -javaagent:"spring-instrument-5.1.2.RELEASE.jar" for ASPECTJ.
And this is exception which i accept when try to get current transaction.
org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope
Also my depend
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-thymeleaf')
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation("org.springframework.boot:spring-boot-starter-websocket")
implementation('org.springframework.boot:spring-boot-starter-security')
implementation("org.springframework.boot:spring-boot-devtools")
Adding aspectjweaver.jar
agent like this: -javaagent:/path/to/aspectjweaver.jar
should solve your problem.