[BUG]记一个FeignClient无法注入bean的错误
springcloud启动报错,错误log如下
2020-06-03 16:25:21.551 WARN 28596 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utils': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.emis.education.service.module.UserServer': FactoryBean threw exception on object creation; nested exception is java.lang.ArrayIndexOutOfBoundsException: 1
2020-06-03 16:25:21.554 INFO 28596 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-06-03 16:25:21.555 WARN 28596 --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method 'close' failed on bean with name 'eurekaRegistration': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
2020-06-03 16:25:21.556 INFO 28596 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-06-03 16:25:21.561 INFO 28596 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2020-06-03 16:25:21.562 INFO 28596 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
查阅网上的资料无果,大部分方案是指向找不到bean,但是我的情况是已经指定了入口文件的@EnableFeignClients,只是依赖无法注入。
最后发现问题起因是在路由层的一个方法与父类冲突或循环引用??根源没有找到,但是我是这样改的,希望对类似的问题有帮助
修改前
// 子类
@Api(tags = "xx")
@RestController
@RequestMapping("xx")
public class ExamPaperController extends BaseController<xxx,xxx,xxx> {
@PostMapping("xxx")
@ApiOperation("xx")
public void create(@RequestParam("file") MultipartFile file,@PathVariable Long chapter) {
// TODO:
}
}
// 父类
@Component
public class BaseController<S extends BaseService<?>,C,U> {
@PostMapping("")
@ApiOperation("create")
public void create(@RequestBody C body) throws NotFoundException {
this.verify(Thread.currentThread() .getStackTrace()[1].getMethodName(),body);
S service = this.getService();
service.create(body);
}
}
修改后(修改方法名)
// 子类
@Api(tags = "xx")
@RestController
@RequestMapping("xx")
public class ExamPaperController extends BaseController<xxx,xxx,xxx> {
@PostMapping("xxx")
@ApiOperation("xx")
public void createXXX(@RequestParam("file") MultipartFile file,@PathVariable Long chapter) {
// TODO:
}
}