When springboot integrates springsecurity, an error occurs:
By viewing the error reporting information, it is found that the errors are reported where redis is used. In the project, redis is used as a cache to store user information. Everything is normal when spring security is not integrated, but there is a problem after the integration. I checked several blogs on the Internet and found that there is a problem when redis serializes and stores user objects.
Key error messages:
Could not read JSON: Unrecognized field "enabled" (class com.xyc.community.entity.User), not marked as ignorable (11 known properties: "authorities", "status", "activationCode", "username", "createTime", "type", "id", "email", "headerUrl", "salt", "password"])
at [Source: (byte[])"{"@class":"com.xyc.community.entity.User","id":134,"username":"www","password":"3d3aeebb9cd302ae581dfa8fedd86ceb","salt":"dfc00","email":"[email protected]","type":0,"status":1,"activationCode":null,"headerUrl":"http://images.nowcoder.com/head/134t.png","createTime":["java.util.Date",1555668837000],"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true}"; line: 1, column: 318] (through reference chain: com.xyc.community.entity.User["enabled"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "enabled" (class com.xyc.community.entity.User), not marked as ignorable (11 known properties: "authorities", "status", "activationCode", "username", "createTime", "type", "id", "email", "headerUrl", "salt", "password"])
at [Source: (byte[])"{"@class":"com.xyc.community.entity.User","id":134,"username":"www","password":"3d3aeebb9cd302ae581dfa8fedd86ceb","salt":"dfc00","email":"[email protected]","type":0,"status":1,"activationCode":null,"headerUrl":"http://images.nowcoder.com/head/134t.png","createTime":["java.util.Date",1555668837000],"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true}"; line: 1, column: 318] (through reference chain: com.xyc.community.entity.User["enabled"])
You can see that several fields are added during serialization because the userdetails interface is implemented in the user class in order to integrate springsecurity. These methods have been rewritten
terms of settlement:
Using the @ jsonignoreproperties annotation, you can ignore these fields when the user object is serialized
Add before user class:
@JsonIgnoreProperties({"enabled","accountNonExpired", "accountNonLocked", "credentialsNonExpired", "authorities"})
Read More:
- [Solved] SpringBoot Integrating Oracle reports errors: ORA-12504, TNS:listener was not given the SID in CONNECT_DATA
- Mybatis integrates Oracle query and reports an error in the datetime type field
- When websocket transmits JSON text, the parse method reports an error
- Unit Android converts c# class to JSON file and reports an error
- (20200916 Solved)Docker||redis-cli Could not connect to Redis at 127.0.0.1:6379: Connection refused
- Mybatis uses step-by-step lazy loading to cause abnormal JSON conversion. The interface 500 reports an error
- When Linux installs redis, it executes make install and reports an error: Make: * * [server. O] error 1 (solved)
- Springboot integration redis reports non null key required (solved)
- Unable to read workspace file ‘D:\angular.json‘: Invalid JSON character: “ “ at
- 【ipfs-api】npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
- HTML method IE8 reports an error, IE8 jQuery Ajax obtains static resources reports an error, typeerror denies access
- QT + MySQL generates an EXE file and reports an error “driver not loaded”. Solution steps
- Hadoop reports an error. Cannot access scala.serializable and python MapReduce reports an error
- The echots in Vue reports an error. After obtaining the DOM element, the chart can be displayed. The console still reports an error
- Easynvr operation log reports an error. Fatal error: concurrent map read and map write troubleshooting
- Use xx [‘xx ‘] = XX to set field value or does not support field: XXX
- Redis cli create creates an error when creating a cluster
- Arduino reports an error when writing a custom library file to solve the problem of not name of type, not declared in this scope
- Centos7 offline installation of redis and PHP extension redis
- The file server reports an error of 413, and the file uploaded by nginx reports an error of 413 request entity too large