sts4.9.0中osgi资源的java类路径问题

y0u0uwnf  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(457)

我的一个spring启动应用程序不能在ide(sts4.9.0)中运行。maven构建运行没有任何问题。但是,如果我想使用引导面板在sts中运行应用程序,则会出现以下错误:

java.lang.NoSuchMethodError: org.springframework.core.type.AnnotationMetadata.introspect(Ljava/lang/Class;)Lorg/springframework/core/type/AnnotationMetadata;
        at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:108)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:276)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at de.berlin.itdz.forms4itdz.kita.app.KitaApp.main(KitaApp.java:27)
    05.01.2021 08:35:44 ERROR [main] 

  ***************************
    APPLICATION FAILED TO START
  ***************************

    Description:

    An attempt was made to call a method that does not exist. The attempt was made from the following location:

        org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:108)

    The following method did not exist:

        org.springframework.core.type.AnnotationMetadata.introspect(Ljava/lang/Class;)Lorg/springframework/core/type/AnnotationMetadata;

    The method's class, org.springframework.core.type.AnnotationMetadata, is available from the following locations:

        jar:file:/Z:/admpetersen/sts-4.9.0.RELEASE/configuration/org.eclipse.osgi/99/0/.cp/lib/spring/spring-core-5.1.4.RELEASE.jar!/org/springframework/core/type/AnnotationMetadata.class
        jar:file:/Z:/admpetersen/.m2/repository/org/springframework/spring-core/5.2.10.RELEASE/spring-core-5.2.10.RELEASE.jar!/org/springframework/core/type/AnnotationMetadata.class

    The class hierarchy was loaded from the following locations:

        org.springframework.core.type.AnnotationMetadata: file:/Z:/admpetersen/sts-4.9.0.RELEASE/configuration/org.eclipse.osgi/99/0/.cp/lib/spring/spring-core-5.1.4.RELEASE.jar

    Action:

    Correct the classpath of your application so that it contains a single, compatible version of org.springframework.core.type.AnnotationMetadata

    05.01.2021 08:35:44 DEBUG [main] Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@388ffbc2, started on Tue Jan 05 08:35:44 CET 2021

正如消息告诉我的那样,加载的spring核心库有两个不同的版本,一个是maven依赖的正确版本,另一个是包含的osgi包中的错误版本。我真的很想纠正消息中建议的类路径,以排除osgi资源。但我不知道怎么做。在项目属性(java构建路径)和springboot应用程序的调试配置中都没有提到osgi库的使用。很明显,它们是隐含的。有人知道如何把它们排除在类路径之外吗?提前谢谢!
一些附加说明:
启用了以下项目方面:dynamicwebmodule4.0、java1.8、javascript 1.0、javaserverfaces2.2
项目内容:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>kita-formular-boot</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
        <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
        <nature>com.jaspersoft.studio.babel.editor.rbeNature</nature>
    </natures>
</projectDescription>
zte4gxcn

zte4gxcn1#

现在我知道了这听起来很简单的原因,但我确实花了一些时间才弄明白。正是一连串的依赖关系导致了这种奇怪的行为:
在我的sts中,我安装了jaspersoft工作室。
在kita formular引导项目的java构建路径中,我添加了另一个项目(kita资源)作为必需的项目。
kita资源包含一些jrxml文件。为了让他们编译,我已经把jasperreports nature添加到了这个项目中。
执行此操作时,jasperreports库依赖项会自动添加到java构建路径中。
这些依赖项包括导致问题的旧的spring核心版本。
通过根据项目需要设置kita资源,kita资源中的所有类路径也包含在kita公式引导中。所以我所要做的就是从kita参考资料中的java构建路径中删除jasperreports库依赖项。很明显,它们不是编译项目所必需的。所有的冲突都消失了!

相关问题