NoSuchMethodError,因为找到了错误的类

时间:2018-07-25 16:11:28

标签: java spring maven

我有一个Sprint Boot应用程序,在部署时出现了NoSuchMethodError。我正在部署到WebSphere 8.5.5.13。我很确定这是因为找到了错误的类或该类的版本。看起来Spring代码正在寻找它自己的类,但是正在从IBM jar文件中找到一个类,并且它加载的类上没有'init()'方法。

请让我知道是否有任何其他信息可以帮助您确定解决方案。

这是我的pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.companygoeshere</groupId>
    <artifactId>eacmanager</artifactId>
    <version>0.0.2-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>EACManager</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-framework-bom</artifactId>
                <type>pom</type>
                <version>5.0.7.RELEASE</version>
                   <scope>import</scope> 
            </dependency>
        </dependencies>
    </dependencyManagement> 

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.extensions</groupId>
            <artifactId>spring-security-saml2-core</artifactId>
             <version>1.0.4.RELEASE</version>
        </dependency>
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-base</artifactId>
        </dependency>
        <dependency>
            <groupId>ca.juliusdavies</groupId>
            <artifactId>not-yet-commons-ssl</artifactId>
            <version>0.3.11</version>
        </dependency>
        <dependency>
            <groupId>org.opensaml</groupId>
            <artifactId>opensaml</artifactId>
             <version>2.6.4</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.ews-java-api</groupId>
            <artifactId>ews-java-api</artifactId>
             <version>2.0</version>
        </dependency>

    </dependencies>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

以下是错误消息:

> com.ibm.ws.exception.RuntimeWarning:
> com.ibm.ws.exception.RuntimeWarning:
> com.ibm.ws.webcontainer.exception.WebAppNotLoadedException: Failed to
> load webapp: Failed to load webapp: Error creating bean with name
> &amp;#39&#59;defaultValidator&amp;#39&#59; defined in class path
> resource
> [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]:
> Invocation of init method failed&amp;#59&#59; nested exception is
> java.lang.NoSuchMethodError:
> javax/validation/Configuration.getDefaultParameterNameProvider&amp;#40&#59;&amp;#41&#59;Ljavax/validation/ParameterNameProvider&amp;#59&#59;
> &amp;#40&#59;loaded from file:/C:/Program Files
> &amp;#40&#59;x86&amp;#41&#59;**/IBM/WebSphere/AppServer/plugins/javax.j2ee.validation.jar** by
> org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@3fb9923&amp;#41&#59;
> called from class
> org.springframework.validation.beanvalidation.LocalValidatorFactoryBean
> &amp;#40&#59;loaded from
> file:/C:/Program&amp;#37&#59;20Files&amp;#37&#59;20&amp;#40&#59;x86&amp;#41&#59;/IBM/WebSphere/AppServer/profiles/AppSrv01/installedApps/TheGarbers3Node01Cell/eacmanagerEAR.ear/eacmanager.war/WEB-INF/lib/spring-context-5.0.7.RELEASE.jar
> by 
> com.ibm.ws.classloader.CompoundClassLoader@79b97694[war:eacmanagerEAR/eacmanager.war]

3 个答案:

答案 0 :(得分:0)

尝试在pom.xml中更改springboot的版本。可以通过引用不同版本的lib文件来工作

2.0.3.RELEASE-> 1.5-.59等

答案 1 :(得分:0)

闻起来像a,您对类路径具有相同依赖项的多个版本。您使用其中一个进行编译,但是正在运行另一个。

运行mvn dependency:tree,您可以看到所带来的一切。 通常,传递依赖关系可能会导致您遇到的问题-即您的Web应用程序同时依赖于库Foo-v1Bar-v1。但是,Foo-v1本身取决于Bar-v2

找到重复的库后,请尝试将每个库更改为相同或最新版本。另一种方法是尝试使用maven的<exclusion></exclusion>,以便您的jar中只有该库的一个版本。

查看此内容:https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

答案 2 :(得分:0)

为此,您需要更改应用程序的类加载器,以便引入正确的依赖关系。

要通过UI进行此操作,请转到应用程序-> WebSphere企业应用程序-> 您的应用程序-> 类加载并更新检测,并将类加载器顺序更改为首先使用本地类加载器加载的类(最后是父类加载器)"causes the class loader to attempt to load classes from its local class path before delegating the class loading to its parent."

如果您要部署EAR并希望将此更改传播到内部应用程序,则可以将 WAR类加载器策略更改为用于应用程序的单个类加载器,或更改单个战争的类加载器(在EAR中,单击管理模块-> 您的模块,然后更改类加载器顺序)。

enter image description here

只要您提供有问题的依赖项版本,就应该通过上述问题。

以下wasadmin.sh脚本将应用以上设置(将 app_name 替换为应用程序的名称):(credit)

dep = AdminConfig.getid('/Deployment:app_name/');
depObject = AdminConfig.showAttribute(dep, 'deployedObject');
AdminConfig.modify(depObject, [['warClassLoaderPolicy', 'SINGLE']]);
classldr = AdminConfig.showAttribute(depObject, 'classloader');
AdminConfig.modify(classldr, [['mode', 'PARENT_LAST']]);