Spring Boot 3 and JSP application won't run as standalone - spring-boot

I upgraded a JSP application to Spring Boot 3 and now it won't start when running as a standalone application.
If I start the application using gradle bootRun it runs fine.
When runing it using java -jar oldnewjspapp.war I get the following stacktrace:
ERROR 7082 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:164) ~[spring-boot-3.0.1.jar!/:3.0.1]
...
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-3.0.1.jar!/:3.0.1]
...
Caused by: java.lang.IllegalStateException: zip file closed
at java.base/java.util.zip.ZipFile.ensureOpen(ZipFile.java:831) ~[na:na]
at java.base/java.util.zip.ZipFile.getManifestName(ZipFile.java:1057) ~[na:na]
at java.base/java.util.zip.ZipFile$1.getManifestName(ZipFile.java:1100) ~[na:na]
at java.base/java.util.jar.JarFile.getManEntry(JarFile.java:937) ~[na:na]
at java.base/java.util.jar.JarFile.checkForSpecialAttributes(JarFile.java:1000) ~[na:na]
at java.base/java.util.jar.JarFile.isMultiRelease(JarFile.java:389) ~[na:na]
at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:68) ~[tomcat-embed-core-10.1.4.jar!/:na]
Does anyone have a solution?

Spring Boot 3 JSP support is broken:
Spring boot app's .jar not working (issue with tomcat-embed-jasper)
https://github.com/spring-projects/spring-boot/issues/33633
https://github.com/spring-projects/spring-boot/issues/32106
The alternatives are:
downgrade your Spring Boot version
extract the war contents and run it that way
generate a regular war (gradle war) and publish it in your favourite web server
turn off the support for Multi-Release JAR Files (this feature is present in Java since release 9): java -Djdk.util.jar.enableMultiRelease=false -jar oldnewjspapp.war

Related

Grail + tomcat org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]

I have been have an issue with my grails prod war deployment.
I have a rest api that i have deployed on a test server with the same specification as the production server.
When i deploy to test (grails test war) everything runs and works alright on tomcat 8 but when i deploy to production (grails prod war), then i get this error:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/client-api]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:727)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1016)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1903)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoSuchMethodError: org.codehaus.groovy.runtime.DefaultGroovyMethods.join(Ljava/lang/Iterable;Ljava/lang/String;)Ljava/lang/String;
at org.grails.config.NavigableMap.<init>(NavigableMap.groovy:38)
Solutions i have tried
Tried with different tomcat versions 8 and 9
I have hanged the tomcat dependency setting from compile to provided
Grails clean, removed the .gradle directory and reimported the project
Any other solution and suggestion is welcome.

java.lang.IllegalStateException: Unable to load config data from 'http://localhost:8888'

I am facing an issue with Spring cloud. The used versions are,
Spring boot version: 2.4.4
Spring cloud version: 2020.0.2
Your input will help me to resolve the microservice startup issue.
I have a spring cloud config server which pick the data from repository and the endpoint
http://localhost:8888/xyz-service/default returning data.
I am trying to read the configuration from microservice which fails to connect to the config server, please refer below error
13:25:09.887 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed
*java.lang.IllegalStateException: Unable to load config data from 'optional:configserver:http://localhost:8888*'
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferences(StandardConfigDataLocationResolver.java:125)
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:112)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.lambda$resolve$1(ConfigDataLocationResolvers.java:114)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:125)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:114)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:106)
at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:101)
at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:93)
at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:81)
at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:119)
at org.springframework.boot.context.config.ConfigDataEnvironment.processInitial(ConfigDataEnvironment.java:230)
at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:217)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:88)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:80)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:100)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:86)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1510)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:362)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
at com.microservice.limitmicroservice.LimitMicroserviceApplication.main(LimitMicroserviceApplication.java:10)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalStateException: File extension is not known to any PropertySourceLoader. If the location is meant to reference a directory, it must end in '/'
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferencesForFile(StandardConfigDataLocationResolver.java:200)
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferences(StandardConfigDataLocationResolver.java:122)
... 35 common frames omitted
Process finished with exit code 0
I see the person did not answer, I have two different applications. They have the same config and the same POM but one gives me this error.
This is the config for both applications, both uses spring boot version 2.4.4, uses java 11, spring cloud 2020.0.2
spring.cloud.config.enabled=false
spring.jmx.enabled=true
management.endpoints.web.exposure.include=*
but the second one fails with similar the error than above
java.lang.IllegalStateException: Unable to load config data from 'optional:configserver:'
Make sure you have the following dependency in your pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
The main reason for this problem is that spring boot does not know how to read the configuration from (for example) repository on github. To solve this problem, you should check whether the following dependency exists in the corresponding module (versions can be different) :
implementation 'org.springframework.cloud:spring-cloud-starter-config:3.1.5'
Connecting this starter should solve your problem

NoClassDefFoundError: Could not initialize class java.awt.image.DataBuffer --> When try to load a PNG Image in Spring Boot

I have a Spring Boot app that basically receives a JSON from the client side and create/return a PDF.
I can load JPG images without problem. But when I load PNG files I have this exception. My Spring Boot "war" app is running inside a Tomcat.
If I execute the Spring Boot app by "java -jar ...", it works well.
Apache Tomcat/9.0.29
Headless OpenJDK 64-Bit VM 1.8
Spring Boot 2.2.1
OpenPDF 1.3
CentOS Linux 7
2020-02-24 01:57:14,042 ERROR [http-nio-8080-exec-217] org.springframework.boot.web.servlet.support.ErrorPageFilter: Forwarding to error page from request [/pdf/create] due to exception [Could not initialize class java.awt.image.DataBuffer]
java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.DataBuffer
at javax.imageio.ImageTypeSpecifier.createComponentCM(ImageTypeSpecifier.java:249)
at javax.imageio.ImageTypeSpecifier$Interleaved.<init>(ImageTypeSpecifier.java:305)
at javax.imageio.ImageTypeSpecifier.createInterleaved(ImageTypeSpecifier.java:399)
at javax.imageio.ImageTypeSpecifier.createSpecifier(ImageTypeSpecifier.java:1169)
at javax.imageio.ImageTypeSpecifier.getSpecifier(ImageTypeSpecifier.java:1118)
at javax.imageio.ImageTypeSpecifier.createFromBufferedImageType(ImageTypeSpecifier.java:901)
at com.sun.imageio.plugins.png.PNGImageReader.getImageTypes(PNGImageReader.java:1531)
at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1318)
at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1614)
at javax.imageio.ImageIO.read(ImageIO.java:1462)
at javax.imageio.ImageIO.read(ImageIO.java:1357)
at com.lowagie.text.ImageLoader.getPngImage(ImageLoader.java:76)
at com.lowagie.text.Image.getInstance(Image.java:284)
at com.company.myapp.service.pdf.pages.Page00.render(Page00.java:69)
at com.company.myapp.service.pdf.pages.PageImpl.<init>(PageImpl.java:27)
at com.company.myapp.service.pdf.pages.Page00.<init>(Page00.java:21)
at com.company.myapp.service.PdfServiceImpl.getPDF(PdfServiceImpl.java:33)
at com.company.myapp.controller.PdfController.generate(PdfController.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

ignore jar packaging inside war maven tomcat plugin?

I am using maven Maven Tomcat 8 plugin to start up my tomcat server locally and deploy a war file with the intellij IDE.
For some reason when I try to start it with maven tomcat 8 plugin, it shows following stack trace and not getting up.
n.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.sun.xml.ws.api.server.AbstractInstanceResolver$1.run(AbstractInstanceResolver.java:84)
at com.sun.xml.ws.api.server.AbstractInstanceResolver$1.run(AbstractInstanceResolver.java:78)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.ws.api.server.AbstractInstanceResolver.invokeMethod(AbstractInstanceResolver.java:78)
at com.sun.xml.ws.server.SingletonResolver.start(SingletonResolver.java:72)
at com.sun.xml.ws.api.server.InstanceResolver$1.start(InstanceResolver.java:238)
at com.sun.xml.ws.server.InvokerTube.setEndpoint(InvokerTube.java:83)
at com.sun.xml.ws.server.WSEndpointImpl.<init>(WSEndpointImpl.java:205)
at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:320)
at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:315)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:158)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:577)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:560)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:303)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:179)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:131)
at com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer.onStartup(WSServletContainerInitializer.java:65)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5210)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1703)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
But when I try to do it with a separate tomcat container (without using maven tomcat 8 plugin or support of IDE), it starts all ok.
I investigated that this happens because of a library (spring-jersey3.jar) that bundles inside my war file. When I remove that from war and try with maven tomcat plugin, it is all ok too. As I found this error happens because it tries to init a spring application context at the start up. But it only happens when I try to do with maven tomcat plugin.
Anyhow I need that lib for my work. I can't exclude it from war.
Does any one know any work around to get rid of this? It may be
configure disabling init the spring application context at start up.
configure maven tomcat 8 plugin to ignore that lib or init process.
Or any other way to do without excluding the lib.

Glassfish embedded with Maven - License FileNotFoundException

i'm using Netbeans 8.0, Windows 8, Java EE 7, Maven web application project and glassfish 4.
When I try to run unit tests with embeddable EJB Container the creation of the container fails with following exception:
SEVERE: Error while expanding archive file
java.io.FileNotFoundException: C:\Users\...\AppData\Local\Temp\gfembed1338945565251414358tmp\applications\classes\license\LICENSE (The system cannot find the file specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
at com.sun.enterprise.deploy.shared.FileArchive.putNextEntry(FileArchive.java:716)
at org.glassfish.internal.deployment.GenericHandler.expand(GenericHandler.java:99)
at com.sun.enterprise.v3.server.ApplicationLifecycle.getContext(ApplicationLifecycle.java:1807)
at com.sun.enterprise.v3.server.ApplicationLifecycle.access$200(ApplicationLifecycle.java:115)
at com.sun.enterprise.v3.server.ApplicationLifecycle$DeploymentContextBuidlerImpl.build(ApplicationLifecycle.java:1670)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:424) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:356)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
at com.sun.enterprise.admin.cli.embeddable.DeployerImpl.deploy(DeployerImpl.java:133)
at com.sun.enterprise.admin.cli.embeddable.DeployerImpl.deploy(DeployerImpl.java:109)
at org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:138)
at org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:134)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:127)
When I try to run simple unit test with a netbeans web app project (no maven project), everything works fine (same temp folder is used). Both unit tests do no more than creating the embedded EJB container.

Resources