我尝试休眠生成代码,但是我得到了这个错误:
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
at org.hibernate.cfg.reveng.JDBCReader.processTables(JDBCReader.java:550)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:74)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:860)
at org.hibernate.cfg.JDBCBinder.readDatabaseSchema(JDBCBinder.java:120)
at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:93)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:43)
at org.jboss.tools.hibernate3_5.console.ConsoleExtension3_5$2.execute(ConsoleExtension3_5.java:255)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.jboss.tools.hibernate3_5.console.ConsoleExtension3_5.buildConfiguration(ConsoleExtension3_5.java:223)我之前的pom.xml有很多依赖项(hibernate-core),但我选择删除它们以查看它是否正常工作,但我仍然收到错误。
<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>pagesjaunes</groupId>
<artifactId>pagesjaunes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>发布于 2014-01-16 10:46:14
典型的java.lang.NoSuchMethodError
检查Javadoc,它说
a. 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.
b. Normally, this error is caught by the compiler; this error can only occur at
runtime if the definition of a class has incompatibly changed.为什么会发生这种情况?
对这种错误最好的解释是-
每当我们试图从.jar文件访问一个方法时,它将在运行时本身被探索;在编译时,这种类型的错误不会被捕获。
例如,举一个例子:
User.java
Class User {
public String firstName;
public String lastName;
public void String getName() {
return firstName +" " +lastName;
}
}假设我们将其导出为jar,并将其导出到的另一个项目中,然后将其用于我们的目的。
注意--在这里包含你的jar文件。
import com.vinayak.User;
class PatternMatch {
public static void main (String args[]) {
User u = new User();
System.out.println(u.accessName());//This will throw a
//No such method error
}
}解释它的全部要点是,如果你试图访问一个当时不存在于该jar中的方法,你将面临这种情况。
所以请检查你使用的是不是正确的版本。它出现在SLF4J 1.7.5中
有关更多了解,请参阅Find where java class is loaded from。
https://stackoverflow.com/questions/21150557
复制相似问题