创建名为"securityConfig"的 bean 时出错,注入自动连线依赖项失败;exception java.lang.IllegalArgumentException



我正在做库管理系统的弹簧启动安全应用程序。当我运行我的应用程序时,我收到提到的错误。有人可以帮我吗?提前感谢!

//Securityconfig

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

ServiceImpl

@Service
public class StudentServiceImpl implements StudentService {
private StudentRepository stuRepository;
public StudentServiceImpl(StudentRepository stuRepository) {
this.stuRepository=stuRepository;
}
@Autowired   
private BCryptPasswordEncoder bCryptPasswordEncoder;        
@Override
public Student findStudentByEmail(String email) {
return stuRepository.findByEmail(email);
}
@Override
public void saveStudent(Student stu) {
stu.setPassword(bCryptPasswordEncoder.encode(stu.getPassword()));
stuRepository.save(stu);
}
}

//错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.queries.users-query' in value "${spring.queries.users-query}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:378) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]

如果我在属性文件中添加查询。 我收到此错误

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'stuserv'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentServiceImpl' defined in file [C:UsersRooteclipse-workspacemanlibtargetclassescomitcinfomanlibserviceStudentServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentRepository': Post-processing of merged bean definition failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]

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

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

您在住宿文件中遗漏了某个属性spring.queries.users-query添加它,错误应该消失

更新:

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

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

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

最新更新