Spring Boot property in @Preauthorize

后端 未结 3 1423
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 08:25

I\'m setting up a Spring Boot (v1.2.6) web project and using Spring Security (v3.2.8). I\'ve found the @PreAuthorize annotation so handy, but I don\'t know if there\'s a way

3条回答
  •  一整个雨季
    2021-01-14 08:40

    This should work:

    @Value("${mysecurity.permit}")
    private Boolean permit;
    

    Then use:

    @PreAuthorize(permit)
    

    But you need to properly set configuration file, to allow Spring access it. Read here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

    UPDATE: Did you configure bean for a property placeholder? For example:

    
        
        
            classpath:com/foo/app.properties
        
        
    
    

提交回复
热议问题