【问题标题】:Issue with @PreAutorize annotation with Spring Security使用 Spring Security 的 @PreAutorize 注释问题
【发布时间】:2014-08-22 20:47:09
【问题描述】:

@PreAuthorize 在 Spring Security 3 中不起作用。

这是我的代码快照。

 @PreAuthorize("hasRole('Admin') or hasRole('Student')")
 public void doSomething(){}

这给了我一个奇怪的错误(参考附件)

【问题讨论】:

  • 你能把类的整个代码展示出来吗?
  • @geoand,我无法在这里添加整个代码,但我确信当我只添加一行时,服务器开始给我错误。如果我删除那条线,它工作正常。
  • @Transactional@Scheduled或其他一些Spring注解时,我们需要知道类或它的任何方法是否被注解
  • 可能是,是的。你试过了吗?最有帮助的是您发布 Spring 配置
  • 感谢@geoand,我通过在 spring-security.xml 中添加 <aop:config proxy-target-class="true"></aop:config> 行来解决问题

标签: spring spring-mvc spring-security pre-authentication


【解决方案1】:

对于其他感兴趣的人..

我通过添加解决了问题

<aop:config proxy-target-class="true"></aop:config> 

spring-security.xml 中的一行

【讨论】:

    猜你喜欢
    • 2015-12-19
    • 2017-04-22
    • 2011-03-05
    • 2011-07-16
    • 2011-03-09
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-26
    相关资源
    最近更新 更多