Spring Boot @EnableTransactionManagement (mode = AdviceMode.ASPECTJ) не работает - PullRequest
0 голосов
/ 26 декабря 2018

Когда я пытаюсь использовать:

@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)

транзакция не работает, но если я использую

@EnableTransactionManagement(mode = AdviceMode.PROXY)

все работает нормально.

Мой код:

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);
    }

Контроллер

@RestController
public class MyController
{
    @Autowired
    MyRepository repository;

    @Transactional
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public void test()
    {
        repository.findById("name");
        System.out.println(TransactionAspectSupport.currentTransactionStatus());
    }
}

Также у меня есть опции VM: -javaagent: «spring-instrument-5.1.2.RELEASE.jar» для ASPECTJ.

И это исключение, которое я принимаю, когда пытаюсь получить текущую транзакцию.

org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope

Также моя зависимость

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

1 Ответ

0 голосов
/ 26 декабря 2018

Добавление aspectjweaver.jar агента вроде этого: -javaagent:/path/to/aspectjweaver.jar должно решить вашу проблему.

...