This is error stack
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfigsList' defined in URL [jar:file:/Users/pupu/Desktop/myproject/bellyTime/bellytimeCustomer/build/libs/bellytimeCustomer-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/malangcute/bellytime/bellytimeCustomer/global/config/SecurityConfigsList.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customOAuth2ForUserService': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [malangcute.bellytime.bellytimeCustomer.global.auth.service.CustomOAuth2ForUserService] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@29ee9faa]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.14.jar!/:5.3.14]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.14.jar!/:5.3.14]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.2.jar!/:2.6.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.2.jar!/:2.6.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.2.jar!/:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.2.jar!/:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.2.jar!/:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.2.jar!/:2.6.2]
at malangcute.bellytime.bellytimeCustomer.BellytimeCustomerApplication.main(BellytimeCustomerApplication.java:23) ~[classes!/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[bellytimeCustomer-0.0.1-SNAPSHOT.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[bellytimeCustomer-0.0.1-SNAPSHOT.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[bellytimeCustomer-0.0.1-SNAPSHOT.jar:na]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[bellytimeCustomer-0.0.1-SNAPSHOT.jar:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customOAuth2ForUserService': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [malangcute.bellytime.bellytimeCustomer.global.auth.service.CustomOAuth2ForUserService] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@29ee9faa]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1302) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1219) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.14.jar!/:5.3.14]
... 27 common frames omitted
Caused by: java.lang.IllegalStateException: Failed to introspect Class [malangcute.bellytime.bellytimeCustomer.global.auth.service.CustomOAuth2ForUserService] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@29ee9faa]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.3.14.jar!/:5.3.14]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.14.jar!/:5.3.14]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267) ~[spring-beans-5.3.14.jar!/:5.3.14]
... 40 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/configurationprocessor/json/JSONException
at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166) ~[na:na]
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309) ~[na:na]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.14.jar!/:5.3.14]
... 42 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.configurationprocessor.json.JSONException
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589) ~[na:na]
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151) ~[bellytimeCustomer-0.0.1-SNAPSHOT.jar:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
... 46 common frames omitted
This is SecurityConfigList.class
@EnableWebSecurity
@Slf4j
public class SecurityConfigsList extends WebSecurityConfigurerAdapter {
private final SecurityProperties securityProperties;
private final CustomOAuth2ForUserService CustomOAuth2ForUserService;
private final OAuth2SuccessHandler oAuth2SuccessHandler;
private final OAuth2FailureHandler oAuth2FailureHandler;
private final TokenProvider tokenProvider;
private final CustomUserService userDetailsService;
private final ObjectMapper objectMapper;
public SecurityConfigsList(
SecurityProperties securityProperties,
CustomOAuth2ForUserService CustomOAuth2ForUserService,
OAuth2SuccessHandler oAuth2SuccessHandler,
OAuth2FailureHandler oAuth2FailureHandler,
TokenProvider tokenProvider,
CustomUserService userDetailsService,
ObjectMapper objectMapper
) {
this.securityProperties = securityProperties;
this.CustomOAuth2ForUserService = CustomOAuth2ForUserService;
this.oAuth2SuccessHandler = oAuth2SuccessHandler;
this.oAuth2FailureHandler = oAuth2FailureHandler;
this.tokenProvider = tokenProvider;
this.userDetailsService = userDetailsService;
this.objectMapper = objectMapper;
}
// private final SecurityProperties securityProperties;
//
// private final CustomOAuth2UserService customOAuth2UserService;
//
// private final OAuth2SuccessHandler oAuth2SuccessHandler;
//
// private final OAuth2FailureHandler oAuth2FailureHandler;
//
// private final TokenProvider tokenProvider;
//
// private final CustomUserService userDetailsService;
//
// private final ObjectMapper objectMapper;
//
//
// private final long MAX_AGES = 3600;
@Bean(BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManager() throws Exception{
return super.authenticationManager();
}
@Autowired
public CookieAuthRepositories cookieAuthRepositories() {
return new CookieAuthRepositories();
}
@Bean
public CorsConfigurationSource corsConfigurationSource(){
CorsConfiguration configuration = new CorsConfiguration();
String frontEndDomain = securityProperties.getCors().getFrontEndDomain();
configuration.addAllowedOriginPattern("*");
// configuration.addAllowedOrigin(frontEndDomain);
// configuration.addAllowedOrigin("http://localhost:3000/");
configuration.setAllowCredentials(true);
configuration.addAllowedHeader("*");
configuration.addAllowedMethod("*");
// configuration.setMaxAge(MAX_AGES);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.cors()
.and()
.httpBasic().disable()
.exceptionHandling().authenticationEntryPoint(new AuthEntryPoint())
.and()
.csrf().disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.formLogin().disable()
.authorizeRequests()
.antMatchers(
"/h2-console/**",
"/oauth2/**",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js",
"/login",
"/join",
"/cookie",
"/cooltime/check",
"/cooltime/**",
"/searchby/**"
).permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.oauth2Login()
.loginPage("/login")
.authorizationEndpoint()
.baseUri("/oauth2/authorize")
.authorizationRequestRepository(cookieAuthRepositories())
.and()
.redirectionEndpoint()
.baseUri("/oauth2/callback/**")
.and()
.userInfoEndpoint()
.userService(CustomOAuth2ForUserService)
.and()
.successHandler(oAuth2SuccessHandler)
.failureHandler(oAuth2FailureHandler)
.and()
.addFilterBefore(new TokenAuthentication(tokenProvider, userDetailsService), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new JWTExceptionFilter(tokenProvider, userDetailsService, objectMapper), TokenAuthentication.class);
}
@Override
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder)
throws Exception {
authenticationManagerBuilder
.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
And this is CustomOauth2ForUserService.class
@Slf4j
@Service
public class CustomOAuth2ForUserService extends DefaultOAuth2UserService {
private final UserRepository userRepository;
public CustomOAuth2ForUserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
//private final TokenProvider tokenProvider;
// private final AuthenticationManager authenticationManager;
@Override
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
OAuth2User oAuth2User = super.loadUser(userRequest);
try {
return processOAuth2User(userRequest, oAuth2User);
} catch (AuthenticationException ex) {
throw ex;
} catch (Exception ex) {
throw new InternalAuthenticationServiceException(ex.getMessage(), ex.getCause());
}
}
private OAuth2User processOAuth2User(OAuth2UserRequest userRequest, OAuth2User oAuth2User) throws NoOAuthProviderException, JSONException {
String registrationId = userRequest.getClientRegistration().getRegistrationId();
Map<String, Object> attributes = oAuth2User.getAttributes();
// System.out.println("here" + attributes);
OAuth2UserInfo oAuth2UserInfo = OAuth2UserInfoFactory.getOAuth2UserInfo(registrationId, attributes);
Optional<User> userOptional = userRepository.findByEmail(new Email(oAuth2UserInfo.getEmail()));
if (userOptional.isPresent()){
User user = userOptional.get();
return UserPrincipal.createUser(user, attributes);
}
User user = registerUser(userRequest, oAuth2UserInfo);
return UserPrincipal.createUser(user, attributes);
}
private User registerUser(OAuth2UserRequest oAuth2UserRequest, OAuth2UserInfo oAuth2UserInfo) throws NoOAuthProviderException, JSONException {
AuthProvider authProvider = AuthProvider.of(oAuth2UserRequest.getClientRegistration().getRegistrationId());
User user = User.builder()
.email(oAuth2UserInfo.getEmail())
.passWord(oAuth2UserInfo.getId())
.phoneNumber("")
.nickName(oAuth2UserInfo.getNickName())
.profileImg(null)
.build();
user.setAuthProvider(authProvider);
return userRepository.save(user);
}
}
I change @Autowired to constructor injection. but it has same error I don't know why this error occurred because has @service annotation so bean can scan the component and this project runs well if not build it. just create error when finished build and run build file. These two classes are custom class so I think it's not dependency problems. What am I miseed? oh and I build with gradle