I’m working with Spring Boot version 1.5.10 and encountering problems when trying to set up a custom error page. My application fails to start and shows an error about missing bean configuration.
The main error message I’m getting is:
APPLICATION FAILED TO START
Description:
Parameter 0 of constructor in com.serviceimpl.ErrorJson required a bean of type 'int' that could not be found.
Action:
Consider defining a bean of type 'int' in your configuration.
The full startup log shows:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-02-15 15:31:45.872 ERROR 6968 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter
I think this might be related to my ErrorJson class constructor expecting an integer parameter that Spring can’t autowire. Has anyone faced similar issues when implementing custom error handling in Spring Boot? What’s the proper way to configure the error page components without breaking the application context?
looks like your ErrorJson needs an int, but Spring can’t autowire it. maybe use @Value to pass it or set a default. double-check if you really need that int in the constructor too.
Had this exact issue with Spring Boot 1.5.x. Spring’s trying to create your ErrorJson class as a bean but can’t figure out what to do with that int parameter in the constructor. You can resolve this by dropping the @Component annotation if ErrorJson is merely a data class, using @Value to inject the int parameter, or creating a factory method in a @Configuration class to manage the int value. Additionally, ensure that ErrorJson is not being component-scanned if it shouldn’t be a Spring-managed bean.
This issue arises when Spring cannot instantiate your ErrorJson class due to its requirement for a constructor parameter. Essentially, Spring attempts to create it as a bean but lacks the integer value necessary for the constructor. I’ve encountered a similar problem in the past—usually, it’s linked to an inappropriate use of annotations like @Component on a straightforward data class. Ensure that ErrorJson does not have Spring-specific annotations if it’s only meant for error representation. If it needs to function as a Spring bean, consider adding a default constructor or using @Autowired with @Value to inject the integer from your properties file.