我正在使用 Spring Boot 开发一个网络应用程序。我已经使用了 Spring Boot 安全性。
如果我使用 spring boot 默认登录页面,身份验证将按预期工作
但它不适用于自定义登录页面。
如果我在 websecurity.java 中配置 http 端点时使用自定义登录页面,我将被重定向到登录页面
下面分享示例代码和我的诊断。
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
@EnableJpaRepositories(basePackageClasses = UserRepository.class)
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomUserDetailsService userDetailsService;
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers("/resources/**").permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage("/loginPage")
.permitAll();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService)
.passwordEncoder(getPasswordEncoder());
}
private PasswordEncoder getPasswordEncoder() {
return new PasswordEncoder() {
@Override
public String encode(CharSequence charSequence) {
return charSequence.toString();
} …Run Code Online (Sandbox Code Playgroud) 我想使用 DI google guice,它在 Java 中工作得很好,但在 scala 中不起作用。这是我的代码:
模块:
class ConfigModule extends AbstractModule{
override def configure(): Unit = {
}
@Provides
@Named("config")
def getConfig(): Config = {
new Config
}
}
Run Code Online (Sandbox Code Playgroud)
配置
class Config {
val config1: String = "Sample"
}
Run Code Online (Sandbox Code Playgroud)
服务
class Service(@Named("config") config:Config) {
def read(): Unit = {
println("Reading")
}
}
Run Code Online (Sandbox Code Playgroud)
主班
object SampleJob {
def main(args: Array[String]): Unit = {
val injector = Guice.createInjector(new ConfigModule)
val service = injector.getInstance(classOf[Service])
service.read()
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
1) Could not …Run Code Online (Sandbox Code Playgroud)