org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'localeResolver' defined in com.restservices.NewSpringbootbuildingblocksApplication: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.LocaleResolver]: Factory method 'localeResolver' threw exception; nested exception is java.lang.StackOverflowError
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.23.jar:5.3.23]
My code is running when I commented below mentioned code
@Bean
public LocaleResolver localeResolver() {
AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
localeResolver.setDefaultLocale(Locale.US);
return localeResolver();
}
You can review your error again. It is throwing below exception.
threw exception; nested exception is java.lang.StackOverflowError
Check your code again you are calling method recursively.
@Bean
public LocaleResolver localeResolver() {
AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
localeResolver.setDefaultLocale(Locale.US);
return localeResolver(); <-- Calling same method again.
}
I think you want to return localeResolver variable instead of calling same method again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.