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.
Related
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.
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.
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.
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
We would like to diversify our production environment and deploy our application instances with different embedded application containers/servers: One instance with Tomcat, one with Jetty and one with Undertow.
Our code does not use anything container-specific, and manually swapping the embedded containers by using a different spring-boot-start dependency works fine.
Is it possible to create a build.gradle that creates three build artifacts (executable JAR files), one for each container? If so - how?