为了账号安全,请及时绑定邮箱和手机立即绑定

创建名为“securityConfig”的 bean 时出错,自动装配依赖项的注入失败;

创建名为“securityConfig”的 bean 时出错,自动装配依赖项的注入失败;

qq_花开花谢_0 2021-09-12 14:23:49
我正在做图书馆管理系统的spring boot安全应用程序。当我运行我的应用程序时,我收到了提到的错误。有人可以帮我吗。提前致谢!//安全配置@Configuration@EnableWebSecuritypublic class SecurityConfiguration  extends WebSecurityConfigurerAdapter{    @Autowired    private BCryptPasswordEncoder bCryptPasswordEncoder;    @Autowired    private DataSource dataSource;    @Value("${spring.queries.users-query}")    private String usersQuery;    @Value("${spring.queries.roles-query}")    private String rolesQuery;    @Override    protected void configure(AuthenticationManagerBuilder auth)            throws Exception {        auth.            jdbcAuthentication()            .usersByUsernameQuery(usersQuery)            .authoritiesByUsernameQuery(rolesQuery)            .dataSource(dataSource)                .passwordEncoder(bCryptPasswordEncoder);    }    @Override    protected void configure(HttpSecurity http) throws Exception {        http.            authorizeRequests()            .antMatchers("/").permitAll()            .antMatchers("/login").permitAll()            .antMatchers("/registration").permitAll()            .antMatchers("/admin/**").hasAuthority("ADMIN").anyRequest()            .authenticated().and().csrf().disable().formLogin()            .loginPage("/login").failureUrl("/login?error=true")            .defaultSuccessUrl("/admin/home")            .usernameParameter("email")            .passwordParameter("password")            .and().logout()            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))            .logoutSuccessUrl("/").and().exceptionHandling()            .accessDeniedPage("/access-denied");    }    @Override    public void configure(WebSecurity web) throws Exception {        web           .ignoring()           .antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/images/**");    }}
查看完整描述

1 回答

?
绝地无双

TA贡献1946条经验 获得超4个赞

如果您阅读错误消息,您可以看到

无法解析值“${spring.queries.users-query}”中的占位符“spring.queries.users-query”

你错过了你的属性文件中的一个属性spring.queries.users-query 添加它,错误应该消失

更新:

如果您阅读了新的错误消息:

java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;

您可以看到显示不兼容的 jar 文件的异常


查看完整回答
反对 回复 2021-09-12
  • 1 回答
  • 0 关注
  • 129 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信