调试 JHipster 应用程序抛出:java.lang.ClassNotFoundException: org.h2.server.web.WebServlet
Posted
技术标签:
【中文标题】调试 JHipster 应用程序抛出:java.lang.ClassNotFoundException: org.h2.server.web.WebServlet【英文标题】:Debugging JHipster application throws: java.lang.ClassNotFoundException: org.h2.server.web.WebServlet 【发布时间】:2021-06-29 16:53:05 【问题描述】:我使用 JHipster 7.0.0 生成了一个应用程序。它的 applicationType 为“monolith”,prodDatabaseType 为“postgressql”,devDatabaseType 为“h2Disk”。
当我运行命令行“./mwnw”时,应用程序完美启动。
当我尝试按照以下说明在 VSCode IDE 中调试应用程序时出现问题:https://www.jhipster.tech/development/。我右键单击Application类的文件(带有@SpringBootApplication注释的那个),单击“Debug Java”菜单,在启动过程中我得到了这个异常:
2021-04-02 18:51:36.143 DEBUG 46054 --- [ main] br.gov.mypackage.config.WebConfigurer : Initialize H2 console
2021-04-02 18:51:36.145 WARN 46054 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: Failed to load and initialize org.h2.server.web.WebServlet
2021-04-02 18:51:36.251 ERROR 46054 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: Failed to load and initialize org.h2.server.web.WebServlet
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:769)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
at br.gov.ancine.JhipsterLearnApp.main(JhipsterLearnApp.java:69)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Failed to load and initialize org.h2.server.web.WebServlet
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:257)
at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.createManager(UndertowServletWebServerFactory.java:345)
at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.getWebServer(UndertowServletWebServerFactory.java:314)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:159)
... 7 common frames omitted
Caused by: java.lang.RuntimeException: Failed to load and initialize org.h2.server.web.WebServlet
at tech.jhipster.config.h2.H2ConfigurationHelper.initH2Console(H2ConfigurationHelper.java:128)
at br.gov.ancine.config.WebConfigurer.initH2Console(WebConfigurer.java:119)
at br.gov.ancine.config.WebConfigurer.onStartup(WebConfigurer.java:52)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:234)
at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory$Initializer.onStartup(UndertowServletWebServerFactory.java:504)
at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:204)
at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:187)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:255)
... 11 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.h2.server.web.WebServlet
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at tech.jhipster.config.h2.H2ConfigurationHelper.initH2Console(H2ConfigurationHelper.java:119)
... 20 common frames omitted
看起来如果 VSCode 没有在类路径中包含 h2database。
【问题讨论】:
您是否在使用 VS Code 启动时激活了dev
配置文件?
【参考方案1】:
答案如下:
在根应用程序文件夹中运行:
mvn spring-boot:run -D"spring-boot.run.jvmArguments"="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
https://***.com/a/68069089/1184154
-
在 vscode launch.json 运行:
“版本”:“0.2.0”, “配置”:[
"type": "java",
"name": "Debug (Launch)",
"request": "launch",
"mainClass": "",
"args": ""
,
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": 8000
]
https://***.com/a/46841712/1184154
【讨论】:
以上是关于调试 JHipster 应用程序抛出:java.lang.ClassNotFoundException: org.h2.server.web.WebServlet的主要内容,如果未能解决你的问题,请参考以下文章
JHipster - 如何在 Eclipse 中仅调试微服务架构中的一个网关(或微服务)?
如何使用带有Jhipster的RabbitMQ创建新的队列?