这是编译过程中出现的错误:
@Controller
@RequestMapping("/registration")
public class RegistrationController {
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private UserRepo userRepo;
@GetMapping
public String registration(){
return "registration";
}
@PostMapping
public String processRegistration(RegistrationForm registrationForm){
userRepo.save(registrationForm.toUser(passwordEncoder));
return "redirect:/login";
}
}
@Configuration
@Autowired
private UserDetailsService userDetailsService;
// шифрование пароля
@Bean
public PasswordEncoder encoder(){
return new BCryptPasswordEncoder(10);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(encoder() );
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/","/home","login","registration").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login").defaultSuccessUrl("/").and()
.logout().logoutUrl("/logout").logoutSuccessUrl("/").permitAll();
}
@NoRepositoryBean
public interface UserRepo extends CrudRepository<User,Long> {
User findByUsername(String name);
}
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'registrationController': Unsatisfied dependency expressed through field 'passwordEncoder'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'inMemoryUserDetailsManager' defined in class path resource [org/springframework/boot/autoconfigure/security/servlet/UserDetailsServiceAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.provisioning.InMemoryUserDetailsManager]: Factory method 'inMemoryUserDetailsManager' threw exception; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'encoder': Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1413) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:774) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:339) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340) [spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329) [spring-boot-2.4.5.jar:2.4.5]
at com.security.Registration.RegistrationApplication.main(RegistrationApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean
with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'userDetailsService';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'inMemoryUserDetailsManager' defined in class path resource
[org/springframework/boot/autoconfigure/security/servlet/UserDetailsServiceAutoConfiguration.class]:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.security.provisioning.InMemoryUserDetailsManager]: Factory method
'inMemoryUserDetailsManager' threw exception; nested exception is
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name
'encoder': Requested bean is currently in creation: Is there an unresolvable circular reference?
public class MyUserDetailsService implements UserDetailsService {
@Autowired
UserRepo userRepository;
@Override
public UserDetails loadUserByUsername(String username) throws
UsernameNotFoundException {
return userRepository.findByUsername(username);
}
}
丹尼斯。stacktrace的最后一行表示:
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name
'encoder': Requested bean is currently in creation: Is there an unresolvable circular reference?
这意味着,当您试图在configure
方法中使用“encoder”bean时,“encoder”bean处于创建阶段。类似的问题在本题中已经得到了解决。我认为您应该像这些问题的答案所建议的那样做--使encoder()
方法静态化。
启动应用程序上下文时出错。若要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2020-08-05 09:53:05.348 错误 46991 --- [ 主] o.s.boot.Spring 应用程序: 应用程序运行失败 组织.Spring框架.豆子.工厂.不满意依赖性异常:创建名称为“产品控制器”的Bean时出错:通过字段“产品存储库”表示的不满意的依赖关系;嵌套的异常是组织.spri
我尝试使用Mybatis XML配置实现一个简单的CRUD应用程序已经是第三天了,我对整个Spring生态系统还是新手。这个问题有点长,但我只分享了要点。 我有一个类: 然后我写了一个映射器 在许多教程和解答之后,我创建了一个,文件也在`Resources文件夹中。 在中,我所做的与在文件中所做的几乎相同 以下是项目结构截图: 嵌套异常是org.springframework.beans.fact
我有这个错误已经有好几个星期了,我不知道如何修复它。类似的堆栈溢出解决方案不适合我的项目。 我目前使用mysql数据库,但遇到这个问题,每当试图启动服务器: StackTrace [错误]无法执行目标组织。springframework。boot:spring boot maven插件:1.5.6。发布:在project iPbackend上运行(默认cli):运行时发生异常。null:Invoc
我查了一些类似的问题,但这些答案帮不了我。 错误 组织。springframework。豆。工厂未满足的依赖项异常:创建名为“accountController”的bean时出错:未满足的依赖项通过字段“accountService”表示;嵌套的异常是org。springframework。豆。工厂NoSuchBeanDefinitionException:没有类型为“com”的合格bean。服务
我想在我的项目中实现Spring Security性。但不管我怎么做,我总是会犯同样的错误。 我创建了必要的类(,,)。它们在同一个包下,但我得到以下错误。 这是发生问题的的一部分 2018-12-31 23:58:10.616信息9952---[main]j.LocalContainerEntityManagerFactoryBean:初始化了持久性单元“默认”的JPA EntityManage