problem description:
if the request method private ModelAndView articleList (Map < String, Object > map)
adds an access control annotation @ PreAuthorize
and uses private
, it will report an error: java.lang.NullPointerException: null
, where null refers to articleService as null. On the surface, it may be the class method permission problem caused by modifiers. Why can you access it without annotating @ PreAuthorize
, but not if you add it? Please explain it in depth.
...
@Autowired
private ArticleService articleService;
...
@GetMapping("/articles")
@PreAuthorize("hasAnyAuthority("admin")")
public ModelAndView articleList(Map<String, Object> map){
List<ArticleDTO> articleListDTO = articleService.articleInfoList();
map.put("articleList", articleListDTO);
return new ModelAndView("article/article_list", map);
}