如何解决如何配置 spring-boot-starter-security
如何根据自己的需要配置 spring-boot-starter-security?
(我在 kotlin 中使用 spring)
我的意思是,我有这个配置文件,但似乎spring容器只是忽略了。
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import java.lang.Exception
@Configuration
@EnableWebSecurity
class WebSecurity : WebSecurityConfigurerAdapter() {
@Bean
public fun encriptator () : BCryptPasswordEncoder{
return BCryptPasswordEncoder();
}
@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
http .authorizeRequests()
.antMatchers("/","/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
}
总是将我重定向到 /login。
并且文件位置与app.kt处于同一级别
解决方法
我得到了解决方案,我的问题是缺少 package 关键字,所以我将配置文件移动到一个名为 config 的包中,现在它可以工作了
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。