Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

preface

Not long ago, I integrated SpringSecurity and JWT to realize login authentication and authorization functions, and encountered some problems in the integration process, which was recorded here.

1. How does Postman add a token request header?

Add request parameters to Headers by checking the previous box

2. What if knife4J online documentation does not request header Settings?

Solution: In the document Management – “personalized Settings” to enable dynamic request parameters, refresh

Spring Security configuration AccessDeniedHandler invalid?

Problem description: when verification authority fail to throw AccessDeniedException abnormalities are not allowed to visit, and I clearly configuration SimpleAccessDeniedHandler to handle exceptions and return message. The GlobalExceptionHandler will catch the AccessDeniedException before the AccessDeniedHandler. Therefore, after GlobalExceptionHandler is configured, AccessDeniedHandler is invalid

Solution: Add AccessDeniedHandler to GlobalExceptionHandler

4, the method report file in the XML file called mybaits cannot be found.

Mybatis XML file in the Java directory, not in the Resources directory. So it’s not packaged at compile time.

Solution: Add it to the POM fileAdd the path of the XML file to the configuration file