IntelliJ: SpringBoot-gradle application fails with "Could not open ServletContext resource" - java

A spring boot application (uses gradle) setup in IntelliJ starts up properly with no exceptions. However, on hitting it with requests via browser/postman throws Internal Server Error.
The application works perfect when started from commandline via
./gradlew bootRun
The exception stack trace says:
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
I suspect something is not right (on classpath) when the application is started from inside IntelliJ - 14.
Any pointers are appreciated.

Related

How do I avoid java.lang.reflect.InvocationTargetException when using Gatling Frontline with compiled code?

I'm using Gatling Frontline to run load tests written in scala with sbt as the build tool. The project compiles, builds, and runs successfully locally. However, when running on a Frontline host, the host fails to connect to the injector pool because the injector process has crashed with an Exception in thread "main" java.lang.reflect.InvocationTargetException. The stack trace indicates that this exception is caused by
java.lang.NoClassDefFoundError: com/google/protobuf/ByteString$Output
and
java.lang.ClassNotFoundException: com.google.protobuf.ByteString$Output.
This error has never occurred locally, during development, as this google package is not used by my project. Could this problem be fixed by changing any of the jvm options supplied by Frontline, or by adding certain system properties or build properties.

WSSecurity proper initialization

I have a problem with WSSecurity configuration in my app. I have all required beans initalized, pointed keystores/truststores etc. Everything works properly when I run it by InteliJ runner(spring boot runner pointing main method) but in case of java -jar on windows it does not work(java -jar on linux works well).
When I run it by java -jar i get an exception in log Caused by: org.apache.wss4j.common.ext.WSSecurityException: You must initialize the xml-security library correctly before you use it
So Ive added org.apache.xml.security.Init.init(); in my configuration class. Then I get other exception: Invocation of init method failed; nested exception is org.apache.wss4j.common.ext.WSSecurityException: Cannot create Crypto class org.apache.wss4j.common.crypto.Merlin
And there Im stuck... That exception brought me there: Cannot create Crypto class org.apache.ws.security.components.crypto.Merlin
But I use openjd with unlimited strength policies already set.
Ive tried to put all program arguments which I see in log while running by IJ to -jar option with no result. Any clues?

How to fix "Error creating bean with name"

My website is/was working just fine. But I am being forced to upgrade the OS of the servers it runs on, because the newer version of a piece of software I need to upgrade, won't run on the old OS. So, now I am in dependency hell.
So, on a test server, I've upgraded the OS from Ubuntu 14.04 to 18.04.1 . I was also forced to use a later version of Java from:
echo $JAVA_HOME
/usr/lib/jvm/java-7-oracle
to
echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64/
And the version of Tomcat from 7 to 8.
Having fiddled a bit (I started this in January, but have only just been able to get back to it, so I can't remember what exactly, though can search the history for clues if required), I can build my application OK, but it fails at the final hurdle:
BUILD SUCCESSFUL Total time: 19 seconds Using CATALINA_BASE:
/var/lib/tomcat8 Using CATALINA_HOME: /usr/share/tomcat8 Using
CATALINA_TMPDIR: /var/lib/tomcat8/temp Using JRE_HOME:
/usr/lib/jvm/java-11-openjdk-amd64/ Using CLASSPATH:
/usr/share/tomcat8/bin/bootstrap.jar:/usr/share/tomcat8/bin/tomcat-juli.jar
Using CATALINA_PID: /root/catalina.pid Tomcat started.
--2019-05-28 16:10:16-- http://localhost:8080/ Resolving localhost (localhost)... 127.0.0.1 Connecting to localhost
(localhost)|127.0.0.1|:8080... connected. HTTP request sent, awaiting
response... 404 2019-05-28 16:10:16 ERROR 404: (no description).
Further investigation reveals:
less /var/log/tomcat8/catalina.out
2019-05-28 16:10:06.418 UTC [localhost-startStop-1] ERROR
org.springframework.web.context.ContextLoader - Context initialization
failed org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'embedController' defined in ServletContext
resource [/WEB-INF/playground-servlet.xml]: Cannot resolve reference
to bean 'homeController' while settin g bean property
'homeController'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'homeController' defined in ServletContext
resource [/WEB-INF/playground-servlet.xml]: Cannot re solve reference
to bean 'execService' while setting bean property 'execService';
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'execService': Invocation of init method
failed; nested exception is javax.ws.rs.ProcessingException:
java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:326)
~[spring-beans-3.2.8.RELEASE.jar:3.2.8.RELEASE]
It should be abundantly clear by now that I don't have much clue what I'm doing. I have spent the afternoon doing lots of googling and looking at lots of Stack Overflow answers, but nothing seems relevant.
that error comes from Spring. For Java 11 support, you'd also need to upgrade Spring to the latest 5.x version (currently 5.2.x).
You may encounter various compatibility issues when upgrading an older environment to Java 11. Unless you absolutely need to upgrade, you may consider staying on a previous version. Java 8 is still being supported.

Tomcat not running for a JAR file

I am using Postman alongside a JAR file that runs a REST service that holds some contacts. However when I try to run the JAR file by using: java -jar ContactListRESTService.jar in Powershell, I am seeing a bunch of errors that Apache Tomcat could not run. Postman also doesn't recognize the localhost.
Caused by: java.lang.IllegalStateException: Tomcat connector in failed state
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:159)
Caused by: java.lang.IllegalStateException: Tomcat connector in failed state
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletCntainer.java:159) ~[spring-boot 1.3.7.RELEASE.jar!/:1.3.7.RELEASE]
I have tried uninstalling and reinstalling JAVA SE per some guidance from a mentor with no results.
If anyone can point me in the right direction please.

VisualVM is unable to profile a web application on Eclipse

I would like to profile my Spring Web Application that is running on Tomcat and Eclipse. I added VisualVM to the Eclipse and followed below steps to run the application for profiling.
Right click on the application name >
Run As >
Run Configuration >
Java Application >
'Selected Project' >
Set 'org.apache.catalina.starup.Boostrap' as a value for Main class,
also selected VisualVM as the Launcher > clicked on Run button.
The VisualVM starts but shows following message:
"Cannot open requested application"
Under local I can see VisualVM, Eclipse and Tomcat.
Following exception will be thrown and shown on console as well:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/juli/logging/LogFactory
at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:59)
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
I reckon the issue is because of wrong server selected. Maybe I should choose Tomcat but not sure how.
Probably an issue with an incomplete classpath when the VisualVM plugin launches Tomcat. You could try to correct the classpath of the start configuration which you created (e.g. try to add bin/tomcat-juli.jar from your tomcat installation) but I doubt this will work easily.
You can try the following:
start your Tomcat, e.g. from Eclipse
then manually start VisualVM: It is actually part of the JDK and located in <JDK dir>/bin/jvisualvm(.exe)
in the application list you should see the Tomcat process and then you can open it with a double click.
Try using Java Mission Control by running jmc. It is included in recent versions of the JDK.
See the getting started doc at http://docs.oracle.com/javacomponents/jmc-5-5/jmc-user-guide/index.html
Run your application, then open the jmc window and connect to the Tomcat process.
This is caused when a class file that your code depends on is not found at run time. This is purely an issue with the class path. Either the class is not exists in the class path or you have a different version of JAR file in the class path. The exception will go away if the class path is corrected.

Categories

Resources