Let’s first look at the error message
Description:
Field businessFeignClient in com.ysc.service.BusinessConfigService required a bean of type 'com.ysc.feignclient.BusinessFeignClient' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.ysc.feignclient.BusinessFeignClient' in your configuration.
Let’s take another look at feign’s configuration information
@SpringBootApplication(
scanBasePackages = "com.ysc",
exclude = {
DataSourceAutoConfiguration.class,
ThymeleafAutoConfiguration.class
})
@EnableFeignClients
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
On the surface, there is no problem with the configuration. Let’s analyze the specific causes of the problem
The annotation @ enablefeignclients conflicts with @ componentscan. Both annotations will search for beans injected into the specified directory@ Enablefeignclients introduces the feignclientsregister class to load spring bean resources
The registerfeignclients method in feignclientsregister obtains the basepackage attribute value in the @ enablefeignclients annotation and injects it. If both annotations are used, @ enablefeignclients will overwrite the directory specified in @ componentscan to restore to the default directory
How to solve this problem:
1. Feignclient can be placed in the same level directory as the application startup class
2. You can specify the bean directory through the clients property in @ enablefeignclients
@EnableFeignClients(clients = {
BusinessFeignClient.class
})
Similar Posts:
- Solution to the problem of consider defining a bean of type ‘xxx’ in your configuration in spring boot auto injection
- Container Cannot Find bean, Field usersMapper in com.imooc.impl.UserServiceImpl required a bean of type ‘com.imooc.mapper.UsersMapper’ that could not be found.
- Springboot + Maven multi module project startup Error: XxxService cannot be found
- Springboot import JPA Error: a bean named ‘entityManagerFactory’ that could not be found
- SpringBoot+Mybatis-plus multi-module project startup Error: xxxmapper or basemapper cannot be found
- Spring boot trample log (@ springbootapplication conflicts with @ componentscan)
- Consider defining a bean of type ‘xxx’ in your configuration. Autowired(required=true)
- Error: no bean named xxxxx available [How to Solve]
- Two ways to implement Spring Boot’s scanmapper interface class
- How to Solve Spring Bean Same Name Conflict