Closed alialrabi closed 2 years ago
I experienced this today when trying to create my 21-Points Health app from scratch.
I started it with ./gradlew
and ran Cypress tests against it with npm run e2e
. Then, I tried to start it in production mode with ./gradlew -Pprod
. It fails to start.
2022-04-30 18:22:41.420 DEBUG 30054 --- [ restartedMain] o.jhipster.health.config.WebConfigurer : Initialize H2 console:bootRun
2022-04-30 18:22:41.421 WARN 30054 --- [ restartedMain] 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
2022-04-30 18:22:41.451 ERROR 30054 --- [ restartedMain] 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:163)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.jhipster.health.TwentyOnePointsApp.main(TwentyOnePointsApp.java:69)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
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:330)
at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.getWebServer(UndertowServletWebServerFactory.java:299)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160)
... 11 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 org.jhipster.health.config.WebConfigurer.initH2Console(WebConfigurer.java:109)
at org.jhipster.health.config.WebConfigurer.onStartup(WebConfigurer.java:50)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:235)
at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory$Initializer.onStartup(UndertowServletWebServerFactory.java:508)
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)
... 15 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.h2.server.web.WebServlet
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:145)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at tech.jhipster.config.h2.H2ConfigurationHelper.initH2Console(H2ConfigurationHelper.java:119)
... 24 common frames omitted
I'll add a bug bounty since this is a blocking issue that's preventing me from working on the JHipster Mini-Book.
Here's my .yo-rc.json
:
{
"generator-jhipster": {
"applicationType": "monolith",
"authenticationType": "jwt",
"baseName": "TwentyOnePoints",
"blueprints": [],
"buildTool": "gradle",
"cacheProvider": "ehcache",
"clientFramework": "angularX",
"clientPackageManager": "npm",
"clientTheme": "none",
"clientThemeVariant": "",
"creationTimestamp": 1651363424551,
"cypressCoverage": false,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"devServerPort": 4200,
"dtoSuffix": "DTO",
"enableGradleEnterprise": false,
"enableHibernateCache": true,
"enableSwaggerCodegen": false,
"enableTranslation": true,
"entitySuffix": "",
"jhiPrefix": "jhi",
"jhipsterVersion": "7.8.1",
"jwtSecretKey": "NWRjNTgyZDc4NmM3Y2E3ZGU2MmNiMGU1ODg1YjI3Y2U2NDE1MDQyM2M3MGIzOTYzMWI0NGJhNTViNzNmYWE4ZTE5NTQyYzBiNTAyYjFkMmJkMDUwY2Y5OTllOGQ0ZGYxZWIzNTA5Y2FhN2UwMjRiMzEyZmYzYTRiNGZjMGY1MWM=",
"languages": ["en", "fr"],
"messageBroker": false,
"nativeLanguage": "en",
"otherModules": [],
"packageName": "org.jhipster.health",
"pages": [],
"prodDatabaseType": "postgresql",
"reactive": false,
"searchEngine": "elasticsearch",
"serverPort": "8080",
"serverSideOptions": ["searchEngine:elasticsearch"],
"serviceDiscoveryType": "no",
"skipCheckLengthOfIdentifier": false,
"skipFakeData": false,
"skipUserManagement": false,
"testFrameworks": ["cypress"],
"websocket": false,
"withAdminUi": true
}
}
$ java --version
openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)
@mraible are on main or the latest 7.x release? Will have a look
Latest: 7.8.1
Can also reproduce it on main. Going to have a detailed look after breakfast.
@mraible can you check if the prod profile is really active? At least running -Pprod results in
2022-05-01 08:14:19.155 INFO 61198 --- [ restartedMain] c.mycompany.myapp.H2GradleProductionApp : No active profile set, falling back to 2 default profiles: "dev", "api-docs"
Will have a look, it looks like the replacement is not working correctly anymore
Found the issue. Will provide a PR before lunch. To be honest I am confused it ever worked. I guess some change in the gradle boot plugin.
I got problem like he , may you help me solve this problem ?
Overview of the issue
Get h2 exception when deploying production
Motivation for or Use Case
Can not deploy production profile
Reproduce the error
https://github.com/alialrabi/mydpp ./gradlew -Pprod
Related issues
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
Suggest a Fix
https://github.com/alialrabi/mydpp
JHipster Version(s)
JHipster 7.8.1
JHipster configuration
Entity configuration(s)
entityName.json
files generated in the.jhipster
directoryBrowsers and Operating System
ubuntu, chrome