当前位置: 首页 > 知识库问答 >
问题:

Spring Boot未满足的依赖关系

蒙光华
2023-03-14

我看了所有类似的问题,没有一个能帮助我,所以事情是这样的:

为了在不同的程序中重现错误,我创建了一个简单的Spring Boot程序。在尝试运行它时,我遇到了一个我无法解决的非常奇怪的错误:

    Error creating bean with name 'testController': Unsatisfied dependency expressed through field 'util'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'biUtil7' defined in class path resource [com/example/demo/configs/RootConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.ionos.ds.elasticsearch.connector.ES7Util] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@3d4eac69]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.6.3.jar:2.6.3]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.6.3.jar:2.6.3]
    at com.example.demo.DemoApplication.main(DemoApplication.java:12) ~[classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'biUtil7' defined in class path resource [com/example/demo/configs/RootConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.ionos.ds.elasticsearch.connector.ES7Util] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@3d4eac69]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656) ~[spring-beans-5.3.15.jar:5.3.15]
    ... 20 common frames omitted
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.ionos.ds.elasticsearch.connector.ES7Util] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@3d4eac69]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.3.15.jar:5.3.15]
    at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:305) ~[spring-context-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1116) ~[spring-beans-5.3.15.jar:5.3.15]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.3.15.jar:5.3.15]
    ... 29 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/common/unit/TimeValue
    at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
    at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166) ~[na:na]
    at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309) ~[na:na]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.15.jar:5.3.15]
    ... 36 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.common.unit.TimeValue
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
    ... 40 common frames omitted

相关类别:

通用域名格式。实例演示。演示应用程序。爪哇:

@SpringBootApplication
@ComponentScan({"com.example.demo.*"})
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

com.example.demo.configs.RootConfiguration.java

@Configuration
@ComponentScan(
        basePackages = {
                "com.example.demo",
                "com.example.demo.controller"
        }
)
public class RootConfiguration {

    @Bean
    public ES7Util biUtil7(@Value("${es.user}") String esUser, @Value("${es.pw}") String esPw) {
        return ES7Util.builder()
                .addHost(new HttpHost("myserver.lan", 9200, "http"))
                .addAuth(esUser,esPw).build();
    }
}

通用域名格式。实例演示。控制器。测试控制器。爪哇:

@RestController
@NoArgsConstructor
public class TestController {

    @Autowired
    private ES7Util util;

    @GetMapping("/TestController")
    public ResponseEntity<JSONObject> main () {
        JSONObject res = new JSONObject();
        res = util.documentUtil().getDoc("testidx","testfile");

        return ResponseEntity.status(HttpStatus.OK).body(res);
    }
}

我可能忽略了什么,但就我所见,没有错误/缺失的注释或任何东西。任何帮助都将不胜感激,谢谢。

共有1个答案

蓬新
2023-03-14

您没有包含任何与您试图构建的ES7Util相关的内容。这可能会阻止你的bean创建吗?

 类似资料:
  • java.lang.noClassDefoundError:scala/collection/gentraversableonce$class at kafka.utils.pool.(pool.scala:28)~[kafka2.10-0.8.1.1.jar:na] at kafka.consumer.FetchRequestandResponseStatsRegistry$.~[kafka2.

  • 我正在尝试实现一个quarkus-extension用于授权/认证。我使用现有的< code > quar kus-small rye-jwt-abx -扩展作为例子。一切似乎都很好,除了我不能注入< code>Principal: 我得到了 对 java.security.主体和限定符类型未满足的依赖关系 [@Default] 注入

  • 我正在尝试创建一个带有Wildfly和数据库连接的EJB Web项目,以持久化我的类“article”。但当我启动我的应用程序时,我得到了错误 包装服务; ArticleDaoImpl

  • 以下是例外情况: 我的代码: 我评论了setCacheable(true),因为它给出了一个错误。有人能帮忙吗?

  • 正在尝试测试我的。。。编译器请求注入,但在为创建bean后,它返回通过字段 代码: 错误: