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

我正在做图书馆管理系统的spring boot安全应用程序。当我运行我的应用程序时,我收到了提到的错误。有人可以帮我吗。提前致谢!


//安全配置


@Configuration

@EnableWebSecurity

public 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/**");

    }

}


qq_花开花谢_0
浏览 130回答 1
1回答

绝地无双

如果您阅读错误消息,您可以看到无法解析值“${spring.queries.users-query}”中的占位符“spring.queries.users-query”你错过了你的属性文件中的一个属性spring.queries.users-query 添加它,错误应该消失更新:如果您阅读了新的错误消息:java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;您可以看到显示不兼容的 jar 文件的异常
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java