springboot +spring security +ajax 遇到的问题

一、在html加载js文件失败

使用了spring security,会对我们的静态文件进行拦截,所以需要配置下,如下:

 

springboot +spring security +ajax 遇到的问题_第1张图片

 

二、前台发送 ajax请求 /addUser接口时,返回403错误,原因是security拦截了POST请求(GET不会拦截)。

我在HTML页面增加了如下信息:

springboot +spring security +ajax 遇到的问题_第2张图片

JS文件我增加了如下信息:
springboot +spring security +ajax 遇到的问题_第3张图片

 

另外,再贴下相关配件文件

spring.mvc.static-path-pattern=/static/**
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.suffix=.html

 

 

你可能感兴趣的:(技能提升)