springboot - kotlin + Spring security的问题

查看:153
本文介绍了springboot - kotlin + Spring security的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题


如图,加了那个注解就会报下面的错
不加就没问题~

解决方案

在类前面加个 open kotlin默认自己写的class是final的,这样就无法被代理了。
还可以了解一下kotlin maven插件 kotlin-maven-allopen:

<plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <configuration>
                    <!-- 可以使得有 pluginOptions 中配置的注解的类为 open-->
                    <compilerPlugins>
                        <plugin>all-open</plugin>
                        <plugin>no-arg</plugin>
                        <plugin>spring</plugin>
                    </compilerPlugins>
                    <pluginOptions>
                        <option>no-arg:annotation=javax.persistence.Entity</option>
                        <option>no-arg:annotation=javax.persistence.Embeddable</option>
                        <option>all-open:annotation=org.springframework.cache.annotation.Cacheable</option>
                        <option>all-open:annotation=org.springframework.cache.annotation.CacheConfig</option>
                        <option>all-open:annotation=org.springframework.context.annotation.Configuration</option>
                    </pluginOptions>
                </configuration>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-noarg</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

这篇关于springboot - kotlin + Spring security的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆