javaspringspring-bootpre-authentication

Springboot @PreAuthorize conflict with @EnableTransactionManagement


I know this sound a bit weird but we run into an issue that when we add @EnableTransactionManagement in the application, all the controllers with @PreAuthorize are not accessible, the swagger cannot discover it and calling the API (with correct permission and role) will encounter 404 not found error.

To solve the issue, either remove the @EnableTransactionManagement in the application config or remove the @PreAuthorize in the controller, but either way is not an ultimate solution.

So I want to ask if any expert knows the cause of this and what we need to do to make things work, as we both need transaction and preauthorize in the app.


Solution

  • Turn out this can be solved by upgrading to spring boot version 2.x

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
    </parent>