这个报错如何解决?DescriptionParameter 0 of constructor in comacpiotcpsminiprogramconfigSecurityConfig required a bean of type orgspringframeworksecuritywebaccessAccessDeniedHandler that could not be foundActi
这个报错提示指出在com.acpiot.cps.miniprogram.config.SecurityConfig的构造函数中需要一个类型为'org.springframework.security.web.access.AccessDeniedHandler'的bean,但是该bean没有被找到。
为了解决这个问题,你需要在你的配置文件中定义一个类型为'org.springframework.security.web.access.AccessDeniedHandler'的bean。你可以通过在你的配置文件中添加如下代码来定义该bean:
@Bean
public AccessDeniedHandler accessDeniedHandler() {
return new MyAccessDeniedHandler();
}
其中,MyAccessDeniedHandler是你自己定义的实现了AccessDeniedHandler接口的类,你需要根据你自己的需求实现该类的逻辑。定义好该bean后,你需要将其注入到SecurityConfig中,以便让Spring能够正确地构造SecurityConfig。
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AccessDeniedHandler accessDeniedHandler;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.exceptionHandling()
.accessDeniedHandler(accessDeniedHandler);
}
}
最后,重新启动你的应用程序,这个报错就应该被解决了
原文地址: http://www.cveoy.top/t/topic/hwsx 著作权归作者所有。请勿转载和采集!