gig*_*dot 5 java spring spring-mvc spring-security
我对此示例的 spring-security bean配置非常相似.@Secured控制器方法的注释只有在不是另一个类的子类的方法上才能正常工作.换句话说,以下代码不起作用(在bean初始化期间引发的异常):
@Controller
@RequestMapping("/systeminfo")
public class SystemInfoController extends AbstractViewableController {
@RequestMapping(method = RequestMethod.GET, value = "/")
@Secured("ROLE_USER") // an exception below was raised
public void view(HttpServletRequest request) {
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'systemInfoController' defined in file [C:\workspace\my\my-webapp
\target\classes\my\webapp\controller\SystemInfoController.class]: Initializa
tion of bean failed; nested exception is org.springframework.aop.framework.AopCo
nfigException: Could not generate CGLIB subclass of class [class my.webapp.c
ontroller.SystemInfoController]: Common causes of this problem include using a f
inal class or a non-visible class; nested exception is net.sf.cglib.core.CodeGen
erationException: java.lang.RuntimeException-->RequestMapping annotation cannot
be found on my.webapp.controller.SystemInfoController$$EnhancerByCGLIB$$e99f
e366
Run Code Online (Sandbox Code Playgroud)
于是我按照指示在这里,并添加proxy-target-class="true"到<global-method-security ...>(不知道这是有关),但安全性方面还是输了.但是,如果删除了超类,则正确应用安全性,即转发到登录页面.
当控制器需要扩展另一个类时,有谁知道发生了什么以及如何解决问题?
这很可能是 spring bean 工厂、spring 注释扫描器或使用 CGLIB 生成子类中的错误。Spring 不应该直接扫描 CGLIB 生成的子类上的注释,因为它们会丢失。它应该扫描其目标类。在这种情况下,它尝试@ResquestMapping扫描my.webapp.controller.SystemInfoController$$EnhancerByCGLIB$$e99fe366.
SystemInfoController然而,因为如果不扩展抽象类,整个事情就会起作用。它表明只有当控制器是子类时注释可能会丢失,这表明这可能是生成代理子类时的错误或CGLIB的限制。
| 归档时间: |
|
| 查看次数: |
4118 次 |
| 最近记录: |