Spring Boot slow startup when it includes a signed jar file - java

I have a spring boot application that is taking over 5 minutes to start. One of the embedded jar files is a Java Cryptography Provider, which is required to do self-integrity check. For each class in the provider's jar, I see the following in the log:
[JarVerifier] providerpackage/.../ClassName.class is signed as
expected
When used as part of the spring-boot jar application and using one of the Spring Boot's launcher classes, this self-integrity check takes about 5 minutes. However, when running the same application as exploded and specifying my own main class it only takes few seconds. The difference is Spring Boot launcher classes use Spring Boot's custom class loader. Is there any way to package the application as a standard Spring Boot application without the slow startup time?
I have already tried to use the provider's jar file as an external jar using -cp and -Dloader.path but the same issue exists.

Related

Spring Boot 2 deployment libraries not visible in windows shared folders

I recently started the process of migrating some of my applications from Spring Boot 1 to Spring Boot 2 when I noticed something strange.
I usually share my deployment files (i.e. the target folder in a spring boot application generated after calling mvn package ) with other members of my development team through the windows "Share..." feature. This worked well in Spring Boot 1 since the generated files would inherit the file permissions from the parent folder.
However, after migrating to Spring Boot 2, I was surprised to find that the jar files in target/<app_name>-<ver>/WEB_INF/lib do not inherit the file sharing preferences from the parent folder. So other members of my development team only see an empty folder instead of the applications jar dependencies.
Strangely, this does not seem to affect any of the other files in the target folder (static files, class files etc.).
Is this a feature or a bug? Is there a way to make sure that the files in this folder are being shared properly?
I have created a batch file that I can run after calling mvn package but this is an extra step that I would like to avoid.

How to add Opneshift config maps files to a spring boot web built in tomcat

Below my project structure
I have multiple modules in one parent maven project.
Many of above modules can also run as independent project including some of them as Openshift applications. These are spring boot applications
Now I want to add one more module as Spring boot web application on Openshift that uses Spring web in build tomcat.
Also I have multiple property files which are specific to environment and I load them as Configmaps on Openshift.
Now when I am trying to deploy the new web application, it is not able to use the Configmaps. It error says property file not found. I am sure this is because the Configmaps are outside of the tomcat and application.
Can I have any work around as I don't want to put those property files in the war while building but should get added when I deploy or start the pod on Openshift.
In short I want something like I can put configmaps as files into the class path spring boot web application that uses in built tomcat.
Mount the ConfigMap-s as volumes at some path and then configure Spring Boot as described here.

Override NewRelic config file used by Cloud Foundry java build pack

I have a Spring Boot application deployed in Cloud Foundry, using the standard Java build pack. Since the app is bound to NewRelic, the build pack injects a NewRelic agent into the environment.
NewRelic documentation talks about adding a newrelic.yml file next to the agent jar location to customize instrumentation behavior. In the CF scenario, can it be located in the classpath of the deployed Spring Boot jar? How do I enable this behavior?
In the CF scenario, can it be located in the classpath of the deployed Spring Boot jar? How do I enable this behavior?
I don't know about that, but two things you can do:
Specify additional configuration options for the NewRelic agent through your bound user provided service.
https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-new_relic_agent.md#user-provided-service-optional
(Optional) Any additional entries will be applied as a system property appended to -Dnewrelic.config. to allow full configuration of the agent.
If you were to fork the Java build pack, you could overlay your own configuration file.
https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-new_relic_agent.md#additional-resources
Your custom file would go here: https://github.com/cloudfoundry/java-buildpack/blob/master/resources/new_relic_agent/newrelic.yml
You probably don't want to fork the build pack though as that creates a whole mess of other problems.
I guess a third option might be to use a .profile.d script, but that's a pain with Java apps because you have to put the files at the root of your JAR file. It could work though.
https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile
Hope that helps!

Spring Boot package web application to .jar

Why Spring Boot by default packaging web applications as .jar ? Are there any advantages over .war ?
Shouldn't be all web applications packed as .war in order to be deployed to real web server ?
I thought that .jar files are for desktop applications whereas .war files are for web applications. since .jar doesn't contain web application components as mentioned here:
Java war vs. jar - what is the difference?
You linked to a question about a WAR vs a JAR, while Spring boot's JAR is indeed a JAR, it contains more than what you usually put inside a JAR. Spring boot comes with an embedded servlet container, inside the JAR itself.
So the difference:
A JAR: Usually contains resources/libraries/desktop applications/...
A WAR: A web application that can be run on a web container
The Spring boot fat JAR: A web application that runs on its own web container
About your question:
Shouldn't be all web applications packed as .war in order to be deployed to real web server?
If you want to run a web application on an existing servlet container, you have to use a WAR file. But the Spring boot JAR comes with its own servlet container, so you can perfectly run it as well.
Which of the two you choose is your own choice. Even though Josh Long's mantra is "Make JAR, not WAR".
By default Spring boot will provide you with embedded Tomcat (in jar). Deploying such jar will make you less dependant on the environment and requires less configuration ("out of the box solution").
See very similar question and its answers.
I think whole point of springboot is speed of development with minimal configuration. So you may think that they provide out of the box solution , that server(tomcat or jetty ) is embedded in the jar.
Also micro-services on cloud are promoting embedded server in jar only so that server can be optimized for application only and there is no need to setup tomcat server for small application.
If you want you can create war of spring boot application
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

Pack two spring boot application in one jar

I have two different spring boot apps - client and server. I use maven and pack this applications into two executable .jar files - client.jar and server.jar. It would be great to create one executable file (.jar or .exe) which would run this two applications sequentially - it would run server.jar first and then it would run client.jar, is it possible in a way?
Thanks, cheers
It is a very bad idea to have more then one applications in one jar. Auto-configuration is very sensitive to dependencies. Spring Boot makes own estimations about application based on those dependencies.
I had two classes annotated with #SpringBootApplication in one jar file. Spring Boot did not initialize database with my data.xml file.

Categories

Resources