java.lang.NoSuchMethodError 介绍

1、 错误内容:java.lang.NoSuchMethodError: com.Boot: method <init>()V not found

此提示内容指,com.Boot没有参数为空的构造函数。提示中指明了异常所在的类和对应的函数。

2、 java文档: 说的很清楚了,是类的变化不兼容导致的异常。通俗的说法是,调用方使用的类定义和加载的类定义不一样,加载的类实际上没有将要调用的方法。

/**
 * Thrown if an application tries to call a specified method of a
 * class (either static or instance), and that class no longer has a
 * definition of that method.
 * <p>
 * Normally, this error is caught by the compiler; this error can
 * only occur at run time if the definition of a class has
 * incompatibly changed.
 *
 * @author  unascribed
 * @since   JDK1.0
 */
public
class NoSuchMethodError extends IncompatibleClassChangeError {

  

3、 如何制造一个NoSuchMethodError:

这里提供两个java代码。放在com目录下。依次执行以下命令:

javac com/Boot.java

javac com/Cloud.java

vim com/Boot.java  把Boot的无参构造函数注释掉,把有参构造函数的注释打开

javac com/Boot.java  重新编译Boot的类文件,最终结果没有无参构造函数

java com/Cloud  此处会出现NoSuchMethodError异常

  

方法提供方
package com;

public class Boot{

	private String name;

	// public Boot (String name){
	// 	this.name = name;
	// }    注意这里的两个构造函数。

	public Boot (){
	}

	public void run(){
		System.out.println(name);
	}
}

======================
调用方
package com;
import com.Boot;
public class Cloud{

	public Cloud (){
	}

	public static void main(String[] args){
		new Boot().run();
	}
}

  

4、原因说明

实际使用的类文件不配套导致的异常。即通常所说的jar包版本不一致导致此问题。

5、实际举例

Spring Boot 2.x 使用 feign 出现此错误。Spring Cloud 1.1调用的构造函数是 new SpringApplicationBuilder(new Object[0]) ,但Spring Boot 2.1 提供的构造函数只有一个

public SpringApplicationBuilder(Class... sources) {
this.application = this.createSpringApplication(sources);
}

java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:120)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:84)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:62)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:342)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
	at com.Application.main(Application.java:22)

  

`

6、解决方式:换依赖jar的版本

原文地址:https://www.cnblogs.com/afraidToForget/p/11576032.html

时间: 2024-10-09 22:31:24

java.lang.NoSuchMethodError 介绍的相关文章

记一次使用修改字节码的方法解决java.lang.NoSuchMethodError

接兔兔国际sdk ane 充值界面选择兔币充值就会闪退, 观察logcat ,NoSuchMethodError: com.tutu.common.a.b.getContext 原来是因为没有方法找不到 04-19 10:10:54.224: E/AndroidRuntime(20315): FATAL EXCEPTION: main 04-19 10:10:54.224: E/AndroidRuntime(20315): Process: com.tutusdk.global.demo, PI

java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.getEnvironment()Lorg/springframework/core/env/ConfigurableEnvironment;问题

在springsecurity学习中,在加入spring有关的jar包后,出现java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.getEnvironment()Lorg/springframework/core/env/ConfigurableEnvironment报错 出错原因:jar包版本有冲突 解决方法:换不同版本的jar包就可以解决问题了

Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: org.testng.TestNG.configure(Lorg/testng/CommandLineArgs;)V

TestNG运行时报以下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.testng.TestNG.configure(Lorg/testng/CommandLineArgs;)V at org.testng.remote.AbstractRemoteTestNG.configure(AbstractRemoteTestNG.java:77) at org.testng.remote.RemoteTestN

Hibernate常见错误:java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibe

hibernate4 与 spring3有点冲突 http://blog.csdn.net/gyflyx/article/details/7632645 整合NoSuchMethodError错误 and 升级Spring3.1RC2 和Hibernate4.0.0CR7遇到的一些问题及解决 2012-02-20 10:33:28|  分类: 编程_SSH |字号 订阅 我使用的是hibernate4和spring3,然后报的错误是 java.lang.NoSuchMethodError: or

java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager

java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager 问题: 使用Springboot打包为war部署于Tomcat7中报错 java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.get

java.lang.NoSuchMethodError

1.错误描述 03-Oct-2014 00:17:23.095 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath 03-Oct-2014 00:17:23.168 INFO [localhost-startStop-1] org.apache.catalina.cor

java.lang.NoSuchMethodError: ognl.SimpleNode.isEvalChain(Lognl/OgnlContext;)Z解决方法

运行JavaEE项目时出现如下错误: java.lang.NoSuchMethodError: ognl.SimpleNode.isEvalChain(Lognl/OgnlContext;)Z at com.opensymphony.xwork2.ognl.OgnlUtil.isEvalExpression(OgnlUtil.java:245) at com.opensymphony.xwork2.ognl.OgnlUtil.checkEnableEvalExpression(OgnlUtil.

java.lang.NoSuchMethodError: org.springframework.dao.IncorrectResultSizeDataAccessException

spring data jpa  运用,在dao类中写自己新增的方法,使用@query写hql语句,出现以下异常: Caused by: java.lang.NoSuchMethodError: org.springframework.dao.IncorrectResultSizeDataAccessException.<init>(Ljava/lang/String;ILjava/lang/Throwable;)V at org.springframework.orm.jpa.EntityM

Spring Boot常见问题(二)Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: org.apache.tomcat.util.scan.StandardJarScanner.setJarScanFilter(Lorg/apache/tomcat/JarScanFilter;

问题描述:通过Spring Boot官方提供的方式,写出如下HelloWorld代码. @Controller @EnableAutoConfiguration public class HelloWorld { @RequestMapping("/wu") @ResponseBody String home() { return "Hello World!"; } public static void main(String[] args) throws Exce