记一次重大的开发运行问题解决

前言

最近已经过完了年,我也结束了我年前的前端工作,转向了我本来就在项目的工作,还是那个将近60w 行代码的系统,这次就比较难受,需要再加一个支付的渠道、修改商户的进件流程。

所以啊,各种各样的问题就有出现了,这个问题真的搞得我头很大,问题来了。

问题简介

Tomcat、 Hibernate、 Spring MVC、 slf4j

这些东西相互交织产生的一个莫名其妙的问题。

问题表述

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
HTTP Status 500 - Servlet.init() for servlet springmvc threw exception

type Exception report

message Servlet.init() for servlet springmvc threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet springmvc threw exception

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)

org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)

org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)

org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)

org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

java.lang.Thread.run(Unknown Source)

root cause

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)

org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)

org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)

org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)

org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)

org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)

org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:664)

org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:630)

org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:678)

org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:549)

org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:490)

org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)

javax.servlet.GenericServlet.init(GenericServlet.java:158)

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)

org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)

org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)

org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)

org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

java.lang.Thread.run(Unknown Source)

root cause

java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl

org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:41)

javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276)

org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:223)

org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean.afterPropertiesSet(OptionalValidatorFactoryBean.java:40)

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)

org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)

org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)

org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)

org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)

org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)

org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:664)

org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:630)

org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:678)

org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:549)

org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:490)

org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)

javax.servlet.GenericServlet.init(GenericServlet.java:158)

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)

org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)

org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)

org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)

org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

java.lang.Thread.run(Unknown Source)

note The full stack trace of the root cause is available in the Apache Tomcat/8.5.4 logs.

Apache Tomcat/8.5.4

第一眼看到这个,脑子没有一丝丝解决的办法,没得办法只能硬上了。

解决办法

  1. 用眼看
    从结果来看,这个显然是不行的。
  2. 度娘
    emmmmmmm……….我拒绝
  3. 谷歌
    stackoverflow 果然牛逼
    1
    2
    3
    I had two version of slf4j-api in my classpath - slf4j-api-1.6.1.jar as well as slf4j-api-1.5.8.jar. I removed the latter and that solved my issue with

    "java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.engine.ConfigurationImpl".

抱着试试的态度。 嘿,还真的是两个

总结

在你遇到问题时,不要慌张,不要放弃,冷静分析,总结前人的经验,当问题解决时,你就会发现,编程真的可能会成为我一生的爱好和职业。

个人备注

此博客内容均为作者学习与官方文档所做笔记,侵删!
若转作其他用途,请注明来源!