Unable to find data for class 'org/springframework/boot/context/web/SpringBootServletInitializer' - spring-boot

I am getting this strange error while trying to start Spring Boot application in Servlet container.
The same WAR starts normally in standalone Tomcat server, but gives the error seen below if started using Gretty Gradle plugin
Any ideas that it means?
Spring-boot 1.3.3, Gradle 2.12, Gretty 1.2.4, Tomcat 8
java.lang.RuntimeException: Reloading agent exited via exception, please raise a jira
at org.springsource.loaded.agent.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:104)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
...
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5066)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
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)
Caused by: org.springsource.loaded.UnableToLoadClassException: Unable to find data for class 'org/springframework/boot/context/web/SpringBootServletInitializer'
at org.springsource.loaded.Utils.loadSlashedClassAsBytes(Utils.java:787)
at org.springsource.loaded.TypeRegistry.getDescriptorFor(TypeRegistry.java:311)
at org.springsource.loaded.TypeDescriptorExtractor$ExtractionVisitor.getTypeDescriptorFor(TypeDescriptorExtractor.java:124)
at org.springsource.loaded.TypeDescriptorExtractor$ExtractionVisitor.findTypeDescriptor(TypeDescriptorExtractor.java:140)
at org.springsource.loaded.TypeDescriptorExtractor$ExtractionVisitor.walkHierarchyForCatchersAndSuperDispatchers(TypeDescriptorExtractor.java:152)
at org.springsource.loaded.TypeDescriptorExtractor$ExtractionVisitor.computeCatchersAndSuperdispatchers(TypeDescriptorExtractor.java:219)
at org.springsource.loaded.TypeDescriptorExtractor$ExtractionVisitor.getTypeDescriptor(TypeDescriptorExtractor.java:81)
at org.sprce.loaded.TypeDescriptorExtractor.extract(TypeDescriptorExtractor.java:51)
at org.springsource.loaded.TypeRegistry.addType(TypeRegistry.java:912)
at org.springsource.loaded.agent.SpringLoadedPreProcessor.preProcess(SpringLoadedPreProcessor.java:302)
at org.springsource.loaded.agent.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:102)
... 42 more

Apparently there is a bug in Gretty related to classloading.
Starting Gretty with WAR e.g. gradlew appRunWar allows to work around it.
There are multiple bugs opened for it:
https://github.com/akhikhl/gretty/issues/199
https://github.com/akhikhl/gretty/issues/209
https://github.com/akhikhl/gretty/issues/148

Related

Spring Initializr pane is blank in IntellJ, for both New Project and New Module

In Intellij, the Spring initializr option is available, but the pane where the options for adding dependencies reside is blank. I tried upgrading my IDE to no avail. This is true when either creating a new project or a new module. This was not an issue until my work issued me a PowerMac (was on Windows before).
When I try to access Initializr, idea.log shows the following stacktrace:
2019-02-12 13:52:16,116 [7322253] ERROR - plication.impl.ApplicationImpl - java.lang.NullPointerException
java.lang.RuntimeException: java.lang.NullPointerException
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1488)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:3018)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:489)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at com.intellij.util.io.HttpRequests.openConnection(HttpRequests.java:609)
at com.intellij.util.io.HttpRequests.access$300(HttpRequests.java:59)
at com.intellij.util.io.HttpRequests$RequestImpl.getConnection(HttpRequests.java:378)
at com.intellij.util.io.HttpRequests$RequestImpl.getInputStream(HttpRequests.java:387)
at com.intellij.util.io.HttpRequests$RequestImpl.getReader(HttpRequests.java:405)
at com.intellij.spring.boot.initializr.SpringInitializrOptionsLoader$1.process(SpringInitializrOptionsLoader.java:104)
at com.intellij.spring.boot.initializr.SpringInitializrOptionsLoader$1.process(SpringInitializrOptionsLoader.java:97)
at com.intellij.util.io.HttpRequests.doProcess(HttpRequests.java:523)
at com.intellij.util.io.HttpRequests.process(HttpRequests.java:499)
at com.intellij.util.io.HttpRequests.access$100(HttpRequests.java:59)
at com.intellij.util.io.HttpRequests$RequestBuilderImpl.connect(HttpRequests.java:352)
at com.intellij.spring.boot.initializr.SpringInitializrOptionsLoader.loadOptions(SpringInitializrOptionsLoader.java:97)
at com.intellij.spring.boot.initializr.SpringInitializrApplicationInfoStep.lambda$loadSpringInitializrOptions$3(SpringInitializrApplicationInfoStep.java:151)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314)
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)
Caused by: java.lang.NullPointerException
at com.sun.security.ntlm.Client.type3(Client.java:161)
at sun.net.www.protocol.http.ntlm.NTLMAuthentication.buildType3Msg(NTLMAuthentication.java:241)
at sun.net.www.protocol.http.ntlm.NTLMAuthentication.setHeaders(NTLMAuthentication.java:216)
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2096)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
... 20 more
How can I fix this?
It looks like a Java bug specific to your NTLM proxy.
It may help if you use IntelliJ IDEA 2019.1 EAP version with JetBrains Runtime 11 version where this issue should be fixed.

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.

ReflectionUtils.makeAccessible() in different .jar files lead to java.lang.NoSuchMethodError Exception on openJDK

i have the following problem: we raised our application from java6 with tomcat6 to java8 with tomcat8. Starting the application on our local machines with Oracle Java 8 worked witouth problem. But on our server we get
java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.makeAccessible(Ljava/lang/reflect/Constructor;)V
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:125)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:251)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4720)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701)
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)
We investigated the problem and the ReflectionUtils.makeAccessible() Method is provided by spring-core-2.0.8.jar and org.springframework.core-3.0.4.RELEASE.jar
Our server is running OpenJDK 8 instead of Oracle Java 8 and it seems like the application tries to use makeAccessible() from the spring-core-2.0.8.jar instead of the org.springframework.core-3.0.4.RELEASE.jar. When we delete the spring-core-2.0.8.jar in our lib Folder the application starts without a problem. Unfortunately the spring-core-2.0.8.jar comes as a maven transitive dependency from a maven hibernate dependency, therefore we need this jar.
Do you have any ideas how to solve this?
Thanks in advance, best regards

Class missing during startup but available afterwards

I'm migrating a project from old Ant scripts to Gradle. For development, I'm using gradle-tomcat-plugin, and the java and war plugins.
The project gets built in a Docker container, which works fine for me but not for my colleague. When he runs gradle tomcatRun, he gets an error like this:
A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/rsa]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:816)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
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)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/rsa]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: java.lang.NoClassDefFoundError: ServletException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.apache.catalina.util.Introspection.getDeclaredMethods(Introspection.java:127)
at org.apache.catalina.startup.WebAnnotationSet.loadMethodsAnnotation(WebAnnotationSet.java:287)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:415)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:892)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5412)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: ServletException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
... 20 more
A child container failed during start
I assume this is referring to javax.servlet.ServletException. However, if I force one of the servlets to throw a ServletException (which I can test because it loads fine on my machine), it can find that class with no problem.
My build file looks something like this (full source here):
providedCompile (
"org.apache.tomcat:tomcat-catalina:$tomcatVersion",
)
compile (
'com.googlecode.lambdaj:lambdaj:2.3.3',
'com.sun.xml.bind:jaxb-impl:2.1',
'commons-io:commons-io:1.3.2',
'commons-net:commons-net:3.4',
'javax.validation:validation-api:1.0.0.GA',
'org.codehaus.jackson:jackson-mapper-asl:1.7.1',
'org.hibernate:hibernate-validator:4.2.0.Final',
"org.springframework:org.springframework.web:$springVersion",
"org.springframework:org.springframework.web.servlet:$springVersion",
'rome:rome:1.0',
)
runtime (
'commons-fileupload:commons-fileupload:1.2',
"org.springframework:spring-oxm:$springVersion",
)
tomcat (
"org.apache.tomcat.embed:tomcat-embed-core:$tomcatVersion",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:$tomcatVersion",
"org.apache.tomcat.embed:tomcat-embed-jasper:$tomcatVersion",
)
Is there another ServletException that I'm missing a .jar for? Or is it that the .jar might not have loaded during server startup, but gets loaded later? The app is currently configured to use servlet API 2.4. I've seen some other threads saying to upgrade it, but changing it to 2.5 didn't help.
build.gradle
web.xml
Dockerfile
OK this is embarrassing: there must have been some stale files hiding in my colleague's source tree, maybe masked by .gitignore. Doing a clean checkout of the repository has "fixed" the problem.
I say "fixed" because we never really got to the bottom of it: the error was saying that it couldn't find ServletException. I implemented my own ServletException in the default package (thanks Thilo for the tip), but it just showed another similar error. Anyway it works now, so chances are it was just a classpath problem involving a file that shouldn't have been in the source tree.

RESTEasy 3 broken with Spring 4.0

I am using Spring 4, Resteasy 3.0.6 and Tomcat 7
Tomcat startup fine but I get a 404 for all REST endpoints.
I think I am running into exactly is described here:
https://issues.jboss.org/browse/RESTEASY-1012
I created that custom class and updated the web.xml
<listener>
<listener-class>com.example.CustomContextLoaderListener</listener-class>
</listener>
However now I get this exception and Tomcat fails to start
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException:
Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].Stand
ardContext[]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.ja
va:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java
:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.
java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.
java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [St
andardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletCo
ntainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer
at org.apache.catalina.startup.ContextConfig.getServletContainerInitiali
zer(ContextConfig.java:1661)
at org.apache.catalina.startup.ContextConfig.processServletContainerInit
ializers(ContextConfig.java:1569)
Any help will be appreciated. Thanks
Answering my own question. The problem was that javax-servlet was a compile dependency so I had to change its scope to provided as that was causing a conflict with Tomcat (I'm using Maven)

Resources