spring Sping Boot 2 -自动连接服务时对Feign客户端的依赖性不满意

o8x7eapl  于 2024-01-05  发布在  Spring
关注(0)|答案(6)|浏览(146)

我有一个非常简单的情况,我已经尝试了一些事情,现在我找不到这个问题的原因。它声称它不能自动连接Feign客户机类,虽然这是我在Sping Boot 1.5.9中完成的。至少我很确定。在我的所有单元测试中,事情都工作正常,虽然我在嘲笑这个客户机。以前它是一个导入库的一部分,但是为了消除我没有正确定位bean,我只是将它添加到同一个项目中。
我不是最有经验的Spring或假装,所以我想知道,如果它是明显的,我错过了这里。
简单的伪装客户端:

  1. @FeignClient(name = "my-other-service")
  2. public interface OtherServiceClient {
  3. @GetMapping(value = "/foo/{fooId}")
  4. @ResponseBody
  5. String getFoo(@PathVariable int fooId);
  6. }

字符串
主要应用类别:

  1. @SpringBootApplication
  2. @EnableDiscoveryClient
  3. @EnableFeignClients
  4. // Had a component scan here when in other module
  5. public class MyServiceApplication {
  6. public static void main(String[] args) {
  7. SpringApplication.run(MyServiceApplication.class, args);
  8. }
  9. }


依赖于虚拟客户端的服务:

  1. @Service
  2. public class FooService {
  3. private final FooRepository fooRepository;
  4. private final BarRepository barRepository;
  5. private OtherServiceClient otherServiceClient;
  6. @Autowired
  7. public OrderService(
  8. FooRepository fooRepository,
  9. BarRepository barRepository,
  10. OtherServiceClient otherServiceClient) {
  11. this.fooRepository= fooRepository;
  12. this.barRepository = barRepository;
  13. this.otherServiceClient = otherServiceClient;
  14. }


由于它可能是一个自动配置的事情,这里是配置报告:

  1. ============================
  2. CONDITIONS EVALUATION REPORT
  3. ============================
  4. Positive matches:
  5. -----------------
  6. ConfigServiceBootstrapConfiguration#configServicePropertySource matched:
  7. - @ConditionalOnProperty (spring.cloud.config.enabled) matched (OnPropertyCondition)
  8. - @ConditionalOnMissingBean (types: org.springframework.cloud.config.client.ConfigServicePropertySourceLocator; SearchStrategy: all) did not find any beans (OnBeanCondition)
  9. ConfigurationPropertiesRebinderAutoConfiguration matched:
  10. - @ConditionalOnBean (types: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor; SearchStrategy: all) found bean 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor' (OnBeanCondition)
  11. ConfigurationPropertiesRebinderAutoConfiguration#configurationPropertiesBeans matched:
  12. - @ConditionalOnMissingBean (types: org.springframework.cloud.context.properties.ConfigurationPropertiesBeans; SearchStrategy: current) did not find any beans (OnBeanCondition)
  13. ConfigurationPropertiesRebinderAutoConfiguration#configurationPropertiesRebinder matched:
  14. - @ConditionalOnMissingBean (types: org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder; SearchStrategy: current) did not find any beans (OnBeanCondition)
  15. EncryptionBootstrapConfiguration matched:
  16. - @ConditionalOnClass found required class 'org.springframework.security.crypto.encrypt.TextEncryptor'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
  17. PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer matched:
  18. - @ConditionalOnMissingBean (types: org.springframework.context.support.PropertySourcesPlaceholderConfigurer; SearchStrategy: current) did not find any beans (OnBeanCondition)
  19. Negative matches:
  20. -----------------
  21. ConfigServiceBootstrapConfiguration.RetryConfiguration:
  22. Did not match:
  23. - @ConditionalOnClass did not find required class 'org.springframework.retry.annotation.Retryable' (OnClassCondition)
  24. DiscoveryClientConfigServiceBootstrapConfiguration:
  25. Did not match:
  26. - @ConditionalOnProperty (spring.cloud.config.discovery.enabled) did not find property 'spring.cloud.config.discovery.enabled' (OnPropertyCondition)
  27. EncryptionBootstrapConfiguration.RsaEncryptionConfiguration:
  28. Did not match:
  29. - Keystore nor key found in Environment (EncryptionBootstrapConfiguration.KeyCondition)
  30. Matched:
  31. - @ConditionalOnClass found required class 'org.springframework.security.rsa.crypto.RsaSecretEncryptor'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
  32. EncryptionBootstrapConfiguration.VanillaEncryptionConfiguration:
  33. Did not match:
  34. - @ConditionalOnMissingClass found unwanted class 'org.springframework.security.rsa.crypto.RsaSecretEncryptor' (OnClassCondition)
  35. EurekaDiscoveryClientConfigServiceBootstrapConfiguration:
  36. Did not match:
  37. - @ConditionalOnProperty (spring.cloud.config.discovery.enabled) did not find property 'spring.cloud.config.discovery.enabled' (OnPropertyCondition)
  38. Matched:
  39. - @ConditionalOnClass found required class 'org.springframework.cloud.config.client.ConfigServicePropertySourceLocator'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)


相关部分的pom...我用的是Maven。

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.0.0.RELEASE</version>
  5. <relativePath/> <!-- lookup parent from repository -->
  6. </parent>
  7. <properties>
  8. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  9. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  10. <java.version>1.8</java.version>
  11. <spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
  12. <spring-restdocs.version>2.0.0.RELEASE</spring-restdocs.version>
  13. <snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
  14. </properties>
  15. <dependencies>
  16. <dependency>
  17. <groupId>org.springframework.boot</groupId>
  18. <artifactId>spring-boot-starter-actuator</artifactId>
  19. </dependency>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-data-jpa</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-security</artifactId>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-starter-web</artifactId>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.springframework.cloud</groupId>
  34. <artifactId>spring-cloud-starter-config</artifactId>
  35. </dependency>
  36. <dependency>
  37. <groupId>org.springframework.cloud</groupId>
  38. <artifactId>spring-cloud-starter-openfeign</artifactId>
  39. </dependency>
  40. <dependency>
  41. <groupId>org.springframework.cloud</groupId>
  42. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  43. </dependency>
  44. <dependency>
  45. <groupId>org.springframework.cloud</groupId>
  46. <artifactId>spring-cloud-starter-oauth2</artifactId>
  47. </dependency>
  48. <dependency>
  49. <groupId>org.springframework.boot</groupId>
  50. <artifactId>spring-boot-devtools</artifactId>
  51. <scope>runtime</scope>
  52. </dependency>
  53. <dependency>
  54. <groupId>com.oracle</groupId>
  55. <artifactId>ojdbc14</artifactId>
  56. <version>10.2.0</version>
  57. </dependency>
  58. <dependency>
  59. <groupId>com.fasterxml.jackson.datatype</groupId>
  60. <artifactId>jackson-datatype-jdk8</artifactId>
  61. <version>2.9.4</version>
  62. </dependency>
  63. <dependency>
  64. <groupId>org.projectlombok</groupId>
  65. <artifactId>lombok</artifactId>
  66. <optional>true</optional>
  67. </dependency>
  68. <dependency>
  69. <groupId>org.hsqldb</groupId>
  70. <artifactId>hsqldb</artifactId>
  71. <version>2.4.0</version>
  72. <scope>test</scope>
  73. </dependency>
  74. <dependency>
  75. <groupId>org.springframework.boot</groupId>
  76. <artifactId>spring-boot-starter-test</artifactId>
  77. <scope>test</scope>
  78. </dependency>
  79. <dependency>
  80. <groupId>org.springframework.restdocs</groupId>
  81. <artifactId>spring-restdocs-mockmvc</artifactId>
  82. <scope>test</scope>
  83. </dependency>
  84. <dependency>
  85. <groupId>org.springframework.security</groupId>
  86. <artifactId>spring-security-test</artifactId>
  87. <scope>test</scope>
  88. </dependency>
  89. </dependencies>
  90. <dependencyManagement>
  91. <dependencies>
  92. <dependency>
  93. <groupId>org.springframework.cloud</groupId>
  94. <artifactId>spring-cloud-dependencies</artifactId>
  95. <version>${spring-cloud.version}</version>
  96. <type>pom</type>
  97. <scope>import</scope>
  98. </dependency>
  99. </dependencies>
  100. </dependencyManagement>
  101. <repositories>
  102. <repository>
  103. <id>spring-snapshots</id>
  104. <name>Spring Snapshots</name>
  105. <url>https://repo.spring.io/snapshot</url>
  106. <snapshots>
  107. <enabled>true</enabled>
  108. </snapshots>
  109. </repository>
  110. <repository>
  111. <id>spring-milestones</id>
  112. <name>Spring Milestones</name>
  113. <url>https://repo.spring.io/milestone</url>
  114. <snapshots>
  115. <enabled>false</enabled>
  116. </snapshots>
  117. </repository>
  118. </repositories>


堆栈跟踪已从一些不太相关的数据中删除...

  1. 2018-03-21 15:07:20.481 INFO 26756 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.2.14.Final}
  2. 2018-03-21 15:07:20.483 INFO 26756 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
  3. 2018-03-21 15:07:20.539 INFO 26756 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
  4. 2018-03-21 15:07:20.930 INFO 26756 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
  5. 2018-03-21 15:07:21.445 INFO 26756 --- [ restartedMain] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
  6. java.lang.reflect.InvocationTargetException: null
  7. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162]
  8. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_162]
  9. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162]
  10. at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162]
  11. at org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.useContextualLobCreation(LobCreatorBuilderImpl.java:113) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  12. at org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.makeLobCreatorBuilder(LobCreatorBuilderImpl.java:54) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  13. at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.<init>(JdbcEnvironmentImpl.java:271) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  14. at ...
  15. at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  16. at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  17. at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  18. at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  19. at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  20. at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  21. at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  22. at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:861) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  23. at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  24. at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  25. .
  26. .
  27. .
  28. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  29. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  30. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  31. at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  32. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  33. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  34. at com.myservice.EqOrderServiceApplication.main(EqOrderServiceApplication.java:14) ~[classes/:na]
  35. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162]
  36. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_162]
  37. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162]
  38. at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162]
  39. at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  40. Caused by: java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.createClob()Ljava/sql/Clob;
  41. ... 49 common frames omitted
  42. 2018-03-21 15:07:22.361 INFO 26756 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  43. 2018-03-21 15:07:23.295 INFO 26756 --- [ restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing FeignContext-dbe-order-detail: startup date [Wed Mar 21 15:07:23 EDT 2018]; parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1290d90c
  44. 2018-03-21 15:07:23.316 INFO 26756 --- [ restartedMain] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
  45. 2018-03-21 15:07:24.048 WARN 26756 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainController' defined in file [<my path>\controller\MainController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderService' defined in file [<my path>\service\OrderService.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.myservice.OtherServiceClient ': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
  46. 2018-03-21 15:07:24.049 INFO 26756 --- [ restartedMain] s.c.a.AnnotationConfigApplicationContext : Closing FeignContext-dbe-order-detail: startup date [Wed Mar 21 15:07:23 EDT 2018]; parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1290d90c
  47. 2018-03-21 15:07:24.051 INFO 26756 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
  48. 2018-03-21 15:07:24.053 WARN 26756 --- [ restartedMain] 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!)
  49. 2018-03-21 15:07:24.055 INFO 26756 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
  50. 2018-03-21 15:07:24.077 INFO 26756 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
  51. Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  52. 2018-03-21 15:07:24.091 ERROR 26756 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
  53. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainController' defined in file [<my path>\controller\MainController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderService' defined in file [<my path>\service\OrderService.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.myservice.OtherServiceClient ': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
  54. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  55. at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  56. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  57. .
  58. .
  59. .
  60. at com.myservice.MyServiceApplication.main(MyServiceApplication.java:14) [classes/:na]
  61. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162]
  62. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_162]
  63. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162]
  64. at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162]
  65. at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  66. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderService' defined in file [<my path>\service\OrderService.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.myservice.OtherServiceClient ': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
  67. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  68. at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  69. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  70. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  71. .
  72. .
  73. .
  74. at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  75. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  76. ... 24 common frames omitted
  77. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.myservice.OtherServiceClient ': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
  78. at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  79. at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  80. at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1645) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  81. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1178) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  82. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:258) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  83. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  84. at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  85. at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1325) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  86. at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1291) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  87. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  88. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  89. at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  90. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  91. ... 38 common frames omitted
  92. Caused by: java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
  93. at feign.Util.checkState(Util.java:128) ~[feign-core-9.5.1.jar:na]
  94. at org.springframework.cloud.openfeign.annotation.PathVariableParameterProcessor.processArgument(PathVariableParameterProcessor.java:51) ~[spring-cloud-openfeign-core-2.0.0.BUILD-20180321.114528-231.jar:2.0.0.BUILD-SNAPSHOT]
  95. at org.springframework.cloud.openfeign.support.SpringMvcContract.processAnnotationsOnParameter(SpringMvcContract.java:238) ~[spring-cloud-openfeign-core-2.0.0.BUILD-20180321.114528-231.jar:2.0.0.BUILD-SNAPSHOT]
  96. at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:110) ~[feign-core-9.5.1.jar:na]
  97. at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:133) ~[spring-cloud-openfeign-core-2.0.0.BUILD-20180321.114528-231.jar:2.0.0.BUILD-SNAPSHOT]
  98. at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:66) ~[feign-core-9.5.1.jar:na]
  99. at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:146) ~[feign-core-9.5.1.jar:na]
  100. at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:53) ~[feign-core-9.5.1.jar:na]
  101. at feign.Feign$Builder.target(Feign.java:218) ~[feign-core-9.5.1.jar:na]
  102. at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:39) ~[spring-cloud-openfeign-core-2.0.0.BUILD-20180321.114528-231.jar:2.0.0.BUILD-SNAPSHOT]
  103. at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:223) ~[spring-cloud-openfeign-core-2.0.0.BUILD-20180321.114528-231.jar:2.0.0.BUILD-SNAPSHOT]
  104. at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:244) ~[spring-cloud-openfeign-core-2.0.0.BUILD-20180321.114528-231.jar:2.0.0.BUILD-SNAPSHOT]
  105. at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:161) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  106. ... 50 common frames omitted
  107. Disconnected from the target VM, address: '127.0.0.1:50881', transport: 'socket'
  108. Process finished with exit code 0


我现在真的很困惑。
编辑:
更新,所以,为了进行更多的调查,因为我确信服务在开始Feign工作之前就启动了,所以我注解掉了对Feign客户端和Feign客户端本身的所有引用,除了应用程序类上的配置注解。我在启动时仍然看到对数据库驱动程序的引用,但应用程序确实在运行。这是我在启动时看到的例外,但没有Feign交互,应用程序将启动。

  1. 2018-03-21 17:04:56.222 INFO 27424 --- [ restartedMain] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
  2. java.lang.reflect.InvocationTargetException: null
  3. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162]
  4. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  5. org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  6. at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  7. at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
  8. Caused by: java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.createClob()Ljava/sql/Clob;
  9. ... 49 common frames omitted


数据库驱动程序是在较旧的一面,所以我可能会看到有关更新到ojdbc8驱动程序,也许,而我在它...

qyswt5oh

qyswt5oh1#

之前在feign client中有一个问题。我猜你也遇到了同样的问题,可能是因为你使用的是旧版本,但是你应该做的是在@PathVariable注解中包含pathVariable名称,比如@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET) String hello(@PathVariable(value = "name") String name);
您可以从here中找到详细信息

aelbi1ox

aelbi1ox2#

当你使用rest feign客户端服务时,我们需要定义确切的@Pathvariable名称。

  1. @GetMapping("/hello-world/from/{from}/to/{to}")
  2. public String getHelloWorld(@PathVariable("from") String from, @PathVariable ("to") String to);

字符串

agxfikkp

agxfikkp3#

在Sping Boot 中,当使用@PathVariable时,如果您使用默认参数名称(从方法参数名称派生),则没有必要显式指定参数名称。
例如,而不是:

  1. @GetMapping("/example/{customerId}")
  2. public ResponseEntity<?> exampleMethod(@PathVariable(value="customerId") BigInteger customerId)

字符串
您可以简单地使用:用途:

  1. @GetMapping("/example/{customerId}")
  2. public ResponseEntity<?> exampleMethod(@PathVariable BigInteger customerId)


这在大多数情况下都能很好地工作,Sping Boot 能够正确地匹配path变量。
但是,如果您遇到Maven插件的问题,特别是3.5.1版本,我建议将插件更新到更新版本。在我的情况下,从版本3.5.1升级到3.8.1解决了这个问题。

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.apache.maven.plugins</groupId>
  5. <artifactId>maven-compiler-plugin</artifactId>
  6. <version>3.8.1</version>
  7. </plugin>
  8. </plugins>
  9. </build>


值得一提的是,此解决方案已使用Sping Boot 版本2.7.7和Spring Cloud版本2021.0.8进行了测试。确保与您的特定版本兼容。

展开查看全部
hivapdat

hivapdat4#

我在@pathvariable上也遇到了同样的问题,当我像下面这样添加@PathVariable的value属性时,问题得到了解决,

  1. @PathVariable(value = "from") String from,
  2. @PathVariable(value = "to") String to);

字符串

brtdzjyr

brtdzjyr5#

Even though there seems to be a problem in the spring-cloud-oepnfiegn,根据我的经验,大多数时候原因不是框架。
问题往往来自这样的东西:你使用一些库,其中包含OpenFeign客户端的服务.在这种情况下,问题往往是在编译这个客户端库. See the related thread in spring-cloud-oepnfiegn bugtracker.
问题是javac默认情况下不会在字节码中保留方法和构造函数的参数名。因此,如果客户端库的作者依赖spring通过简单的参数名来解析@PathVariable-这根本不起作用-所有信息都已经被删除了。
为了解决这个问题,你需要:

  • 在客户端库中向路径变量添加显式的@PathVariable("someVar")Map,然后重新编译
  • 或者你需要使用-parameters标志重新编译客户端。这个标志将包含关于参数名称的元数据到字节码中,spring将在没有任何额外提示的情况下解析Map。

不幸的是,我不知道如何修复它,除非你没有访问库的源代码。希望它有所帮助。

bqucvtff

bqucvtff6#

  1. @GetMapping(value = "/foo/{fooId}")
  2. @ResponseBody
  3. String getFoo(@PathVariable(value="fooId") int fooId);

字符串
将尽

相关问题