使用Spring 3.2和異步支持。安全上下文匿名Callable
方法在SecurityContext中找不到認證對象 - 帶異步支持的Servlet 3
@RequestMapping(value = "/home", method = RequestMethod.GET)
public Callable<String> home(final Model model) {
return new Callable<String>() {
@Override
public String call() throws Exception {
model.addAttribute("homeService", homeService.findId(1));
return "home";
}
};
}
內輸了一次這是適用於一個bean servlet-context.xml
<beans:bean id="homeService" class="example.service.HomeServiceImpl" scope="request">
<security:intercept-methods>
<security:protect access="ROLE_USER" method="find*"/>
</security:intercept-methods>
</beans:bean>
這裏面的安全性裝飾是錯誤,因爲安全上下文不存在: org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext