创建了一个实现AuthenticationSuccessHandler
的类,并添加了@Component
守护进程以将其与Spring Security配置对象相关联。
https://zapodaj.net/b3085e4c1cd43.png.html
@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {..}
IntelliJ向我显示了一条消息
无法自动装配。没有'CustomAuthenticationSuccessHandler'找到类型
答案 0 :(得分:2)
即使应用程序运行正常,Intellij也无法始终解决自动装配问题。
如果它运行正常并且您没有得到编译错误,请忽略它。
尝试运行rebuild project
来修复它。
您也可以将组件列表添加到组件扫描
@ComponentScan(basePackages = { "com.a.b", "com.a.c" })
答案 1 :(得分:0)
无法自动装配。没有'CustomAuthenticationSuccessHandler' 找到类型
这表示它无法找到#34; CustomAuthenticationSuccessHandler "在容器中。您可能已在 AppConfig 类中定义了一些导入 SecurityConfig 类并已定义组件扫描的bean。但是SecurityConfig并不知道要扫描的包和bean初始化,因为它没有在它的上下文中完成。
您的securityConfig代码应该具有如下代码
@Configuration
@EnableWebSecurity
@ComponentScan(basePackages = { "com.test"})
public class SecurityConfig extends WebSecurityConfigurerAdapter {
----
----
@Bean
public CustomAuthenticationSuccessHandler authenticationSuccessHandlerBean() throws Exception {
CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler =new CustomAuthenticationSuccessHandler();
//Some basic initialization
return customAuthenticationSuccessHandler;
}
}
上面的代码允许您自动装配 CustomAuthenticationSuccessHandler 类。