Skip to content
Advertisement

BeanCreationException when creating Bean of type org.springframework.web.servlet.LocaleResolver

I’m trying to apply internationalization in a Spring Boot app by following some guide. For some reason, in the guide that I’m following it works but not on my local. I can’t figure out why.

The error I am getting in console is :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘localeResolver’

JavaScript

I am aware that when Spring creates a Bean, it looks for a no-argument constructor. Is there an alternative way to make this work where the @Bean definitions are in the class marked with @SpringBootApplication instead of a separate class marked with @Configuration?

Thank you.

Edit : Below is a more detailed log info

JavaScript

Advertisement

Answer

The return statement in your localeResolver() @Bean method is calling the method again:

JavaScript

This will result in a StackOverflowError as each call to localeResolver() will make another call to the same method. Presumably, this is the cause of the BeanCreationException.

I assume you want to return the localResolver local variable so the () should be removed:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement