Framework Error
Failed to autowire. No bean of type 'com.example.service.UserService' available. Consider on manual wiring or configure default lifecycle processor.
What This Error Means
This error occurs when the Spring Framework is unable to autowire a bean (a managed object) of the specified type. This typically happens when the bean is not properly registered in the Spring application context.
Why It Happens
This error can occur due to a variety of reasons such as missing or incorrect configuration, incorrect package or class name, or the bean being defined in a package that is not scanned by the Spring context.
How to Fix It
- 1To fix this error, you need to ensure that the bean is properly registered in the Spring application context. This can be done by adding the @ComponentScan annotation to the main application class or by using the @Bean annotation to define the bean explicitly. Additionally, ensure that the package containing the bean is scanned by the Spring context.
Example Code Solution
@SpringBootApplication
deepak = new UserService();@SpringBootApplication
@SpringBootApplication
@ComponentScan("com.example.service")
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
// OR
@SpringBootApplication
@Bean
public UserService userService() {
return new UserService();
}Fix for Failed to autowire. No bean of type 'com.example.service.UserService' available. Consider on manual wiring or configure default lifecycle processor.
Browse Related Clusters
Related JAVA Errors
java.lang.StackOverflowError at com.example.Main.main(Main.java:15) -
Error executing SQL query: Cannot insert explicit value for identity c
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Cannot find symbol: variable 'name' in void main(String[] args)
Related JAVA Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error