お世話になっております。
Java初心者です。
表題のエラーについての質問になります。
実現したいこと
JavaのsprngBootというものでログイン機能を実装しています。
プログタムを実行してみたところ、下記エラーが発生いたしました。
原因について調べているのですが解決できず、些細なことでもごご教授いただけますと幸いです。
発生しているエラーメッセージ
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. [2m2022-03-06 14:39:52.367[0;39m [31mERROR[0;39m [35m9168[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Application run failed org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'webSecurityConfig': Requested bean is currently in creation: Is there an unresolvable circular reference? at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:355) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:227) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:410) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.resolveBeanReference(ConfigurationClassEnhancer.java:362) ~[spring-context-5.3.16.jar:5.3.16] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:334) ~[spring-context-5.3.16.jar:5.3.16] at login.app.config.WebSecurityConfig$$EnhancerBySpringCGLIB$$b205d0c6.passwordEncoder(<generated>) ~[classes/:na] at login.app.config.WebSecurityConfig.configure(WebSecurityConfig.java:86) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] (一部省略)
該当のソースコード
WebSecurityConfig
1package login.app.config; 2 3 4import org.springframework.beans.factory.annotation.Autowired; 5import org.springframework.context.annotation.Bean; 6import org.springframework.context.annotation.Configuration; 7import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 8import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9import org.springframework.security.config.annotation.web.builders.WebSecurity; 10import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 11import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 12import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 13 14import login.app.controller.employeeListController; 15import login.app.service.UserDetailsServiceImpl; 16 17/** 18 * SpringSecurityを利用するための設定クラス 19 * ログイン処理でのパラメータ、画面遷移や認証処理でのデータアクセス先を設定する 20 * @author aoi 21 * 22 */ 23@Configuration 24@EnableWebSecurity 25public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 26 27 28 @Autowired 29 private UserDetailsServiceImpl userDetailsService; 30 31 //フォームの値と比較するDBから取得したパスワードは暗号化されているのでフォームの値も暗号化するために利用 32 @Bean 33 public BCryptPasswordEncoder passwordEncoder() { 34 BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); 35 return bCryptPasswordEncoder; 36 } 37 38 /** 39 * 認可設定を無視するリクエストを設定 40 * 静的リソース(image,javascript,css)を認可処理の対象から除外する 41 */ 42 @Override 43 public void configure(WebSecurity web) throws Exception { 44 web.ignoring().antMatchers( 45 "/images/**", 46 "/css/**", 47 "/javascript/**" 48 ); 49 } 50 51 /** 52 * 認証・認可の情報を設定する 53 * 画面遷移のURL・パラメータを取得するname属性の値を設定 54 */ 55 @Override 56 protected void configure(HttpSecurity http) throws Exception { 57 http 58 .authorizeRequests() 59 .anyRequest().authenticated() 60 .and() 61 .rememberMe() 62 .and() 63 .formLogin() 64 .loginPage("/login") //ログインページはコントローラを経由しないのでViewNameとの紐付けが必要 65 .loginProcessingUrl("/sign_in") //フォームのSubmitURL、このURLへリクエストが送られると認証処理が実行される 66 .usernameParameter("username") //リクエストパラメータのname属性を明示 67 .passwordParameter("password") 68 .defaultSuccessUrl("/employeelist") 69 .failureUrl("/login?error") 70 .permitAll() 71 .and() 72 .logout() 73 .logoutUrl("/logout") 74 .logoutSuccessUrl("/login?logout") 75 .permitAll(); 76 } 77 78 /** 79 * 認証時に利用するデータソースを定義する設定メソッド 80 * ここではDBから取得したユーザ情報をuserDetailsServiceへセットすることで認証時の比較情報としている 81 * @param auth 82 * @throws Exception 83 */ 84 @Autowired 85 public void configure(AuthenticationManagerBuilder auth) throws Exception{ 86 auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); 87 /* 88 auth 89 .inMemoryAuthentication() 90 .withUser("user").password("{noop}password").roles("USER"); 91 */ 92 } 93 94} 95
補足情報
・データベースはpgAdmin4を使用しております。
・その他必要なソースがありましたらご連絡いただけますと幸いです。
何卒よろしくお願いいたします。
あなたの回答
tips
プレビュー