java.lang.NoSuchMethodError Introduction

1, the error content: java.lang.NoSuchMethodError: com.Boot: method <init> () V not found 

Content refers to this prompt, com.Boot no parameter is empty constructor. Prompt indicates the type and function of the corresponding abnormality is located.

 

2, java document: say very clearly, is not compatible with the class changes caused by abnormal. Popular argument is that the caller used the class definition and the definition of the class load is not the same, the method does not actually loaded class will be called.

/**
 * 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, how to make a NoSuchMethodError:

Here are two java code. Placed under the com directory. In turn execute the following command:

javac com / Boot.java 

javac COM / Cloud.java 

vim COM / Boot.java Boot of the no-argument constructor commented, there is the argument constructor comment open 

javac com / Boot.java recompiling class files Boot eventually no results no-argument constructor 

java com / Cloud here will appear abnormal NoSuchMethodError

  

Method Provider 
Package COM; 

public class the Boot { 

	Private String name; 

	// public the Boot (String name) { 
	// this.name = name; 
	//} Note that here two constructors. 

	the Boot public () { 
	} 
	
	public void RUN () { 
		System.out.println (name); 
	} 
} 

====================== 
caller 
package com; 
com.Boot Import; 
public class Cloud { 

	public Cloud () { 
	} 

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

  

4 reasons explained

Class files do not match the actual use caused by abnormal. Jar package known as the inconsistent versions cause this problem.

 

5, the actual example

Spring Boot 2.x use feign this error. Spring Cloud 1.1 constructor call is new SpringApplicationBuilder (new Object [0]), but the constructor Spring Boot 2.1 provides only one

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, solution: change dependent jar version

Guess you like

Origin www.cnblogs.com/afraidToForget/p/11576032.html