Vote count:
0
I'm interested in why does not work @Autowired annotation (IoC), when I add @Secured annotation in my controller.
@Controller
@RequestMapping("/")
public class HelloController {
@Autowired
private ApplicationContext applicationContext;
@ModelAttribute
private String test() {
return "test";
}
@Secured("hasRole('ROLE_USER')")
@RequestMapping(value = "test", method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Hello world!");
return "hello";
}
}
I found out that the problem is that when using @ModelAttribute method as private, then in runtime controller created as a proxy object in this case, fails spring Dependency Injection. In logs all clean, but attempts to access the property applicationContext causes NullPointerException.
I have never seen the recommendation (or rule) to create methods width @ModelAttribute annotation as public. Without @Secured annotations all good work.
I want to understand why this happens, it can bug?
Thanks.
asked 36 secs ago
Aucun commentaire:
Enregistrer un commentaire