使用了springSecurity验证后,跳转到某个页面时出现错误:NotReadablePropertyException: Invalid property ‘principal.originAdmin’ of bean class [org.springframework.security.authentication.AnonymousAuthenticationToken]: Bean property ‘principal.originAdmin’ is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
可能是该页面中用到了某些属性,比如这样:
<security:authentication property="principal.userName"/><br/>
但是用户登录时又没有把这些信息存到UsernamePasswordAuthenticationToken中
比如登录代码是这样的
builder.inMemoryAuthentication().withUser("username").password("123456").roles("USER");
解决办法就是要么不要在页面上获取不存在的属性,要么封装好用户信息再登陆,比如这样:
builder.userDetailsService(userDetailsService)
.passwordEncoder(getBCryptPasswordEncoder());