SpringBoot整合Spring Security时遇到的错误

小白一枚 ==

这两天自己学习springboot,并且尝试整合security,大问题没有,小问题一堆。
所以以此来记录遇到的问题。

首先 版本问题。。 跟着网上视频学习,自己在maven库中找依赖的时候,都是选择的较新的,结果发生了一些不(真)大(日)不(了)小(狗)的问题,导致我本来不怎么费力地一次学习,变得难以忘怀。
pom.xml先摆这了

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo04-mybaties</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo04-mybaties</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version>
        <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
        <thymeleaf-extras-springsecurity.version>3.0.4.RELEASE</thymeleaf-extras-springsecurity.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        </dependency>

        <!--引入html-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <!-- 引入druid数据源-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.18</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

在原本创建项目的时候,springboot版本使用的是2.1.x(忘了。。),

<dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>

使用的4这个版本,html页面引入的是

<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

结果嘛,所有地方都不报错,但是,启动页面效果如下。。。。
启动首页
对,就是html中插入的 th:xx 与 sec:xx都不管用,但是登陆还注销还是好使的。
然后就是上网一顿查,有说把 thymeleaf-extras-springsecurity4 改成5,
html中的 xmlns:sec=“http://www.thymeleaf.org/thymeleaf-extras-springsecurity4” 也改成5。
嗯。。。pom.xml改成5是没啥问题,但是html中改成5就如下所示了。
在这里插入图片描述
失效了啊 亲。。。整了半天也是不知道怎么回事,最终,以把springboot版本改为2.0.x结束了此问题。
紧接着下一个问题出现了,页面显示没问题,th: xx 与 sec: xx 也没问题,注销 。。。 404。。。
好吧 只能接着解决 脑子不好但是我又度娘啊 然后就找啊找 过程省略30分钟。。。
最终解决方式
在这里插入图片描述
好像就是说post请求被拦截了还是怎么了 。。 这还没有看。只能先用着了

具体问题主要就是这俩。。。 我TM也是服了我自己了 233.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值