Tomcat 8.0.26部署时出现java.lang.NoSuchMethodError错误求助
NoSuchMethodError with JBoss Logging & Hibernate in Tomcat 8.0.26 Hey there, let's tackle this frustrating error you ran into after firing up Tomcat 8.0.26 with ./startup.sh. First, let's recap the error you saw for clarity:
28-Mar-2018 15:07:58.926 SEVERE [localhost-startStop-2] org.apache.catalina.core.StandardContext.listenerStart 发送上下文初始化事件至ie.company.web.AppContextListener监听器实例时发生异常 java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object; at org.hibernate.ejb.Ejb3Configuration.(Ejb3C...
What's causing this?
This is a classic classpath conflict issue. The root problem is that the version of JBoss Logging present in your classpath is too old—Hibernate's EJB3 module (used by your app's AppContextListener) expects a version of JBoss Logging that has the getMessageLogger(Class, String) method, but the one being loaded doesn't include it.
Step-by-Step Fixes
Track down conflicting JBoss Logging JARs
Check two key locations for duplicate or outdatedjboss-logging*.jarfiles:- Tomcat's global
lib/directory - Your web application's
WEB-INF/lib/directory
It's common to have an old version bundled with Tomcat or accidentally included via your app's build dependencies.
- Tomcat's global
Standardize on a compatible JBoss Logging version
For Hibernate EJB3 (typically Hibernate 4.x+), you need at least JBoss Logging 3.1.0.GA—we recommend using 3.3.1.Final for broad compatibility with most Hibernate 4.x releases.- Delete all old
jboss-logging*.jarfiles from both locations - Place the correct version only in your app's
WEB-INF/lib/(this avoids clashing with Tomcat's global libraries)
- Delete all old
Verify Hibernate & JBoss Logging version alignment
Double-check your build tool (Maven/Gradle) to ensure you're pulling in the right JBoss Logging version for your Hibernate release:- Hibernate 4.3.x → JBoss Logging 3.3.1.Final
- Hibernate 5.x → JBoss Logging 3.3.0.Final or newer
Use dependency exclusion rules if a transitive dependency is pulling in an old JBoss Logging version.
Quick Debugging Trick
If you're still unsure which JAR is causing the issue, start Tomcat with the -verbose:class flag:
./startup.sh -verbose:class
This will log every class that gets loaded, so you can trace exactly which jboss-logging*.jar is providing the org.jboss.logging.Logger class missing the required method.
内容的提问来源于stack exchange,提问作者Rodrigo

