Spring Framework hosting - spring

I am trying Java with Spring Framework for my own web project. I've asked some traditional JSP web hosting firms which supports Tomcat and they said they do not support Spring Framework. I am confused about this situation. What is the different requirements between JSP and Spring Framework? I was thinking both of them runs on JVM such as Tomcat and they do not need any difference things. Does Spring Framework need different jar files, or different software on server?

Building a Spring application results in a jar with an embedded webserver (most of the times tomcat, but you can change this in the pom.xml/build.gradle).
I used to host my Spring applications on a VPS or Amazon EC2 instance. Something like that. You can just install Java on it and run your jar. No extra installations of webservers needed.

Ok, let get it straight, just summarizing what have been said:
Use Spring MVC, without spring boot.
Use Spring Boot, and create a war file.

Related

How to make my spring boot application online on my domain?

I have recently learned how to work with Spring boot. Now, I have an application which works locally without any problem. Now, I would like to know how I can make it available as a website.
I have got a free web host from here and have followed the instructions to create a war file for my project. But I don't know what I should do with this war file and how I should use it to have my web page online.
In the meantime, my code is using Atlas Mongodb in it. Is using a database problematic? Should I consider something special for that?
Thanks in advance,
Shared hosting like 000webhost do not support Spring boot Hosting. As it was said earlier to host spring boot you have two choices either you host jar or war file. War is the traditional way of hosting it which needs Apache tomcat server and Jar is the Modern way which supports cloud based solutions. To host your solution you can create an account with AWS(Amazon web services) or GCP (Google Cloud Platform) and you will get free credits to use for a while or you can use Heroku(https://devcenter.heroku.com/articles/deploying-spring-boot-apps-to-heroku) which is pretty much easier to use, its free also. For the database if you are using (https://www.mongodb.com/cloud/atlas) then you are good. All the best
If you are using Spring Boot, which have an embedded tomcat. You can just pack your project to a jar file, put the jar file to the server, and then simply execute it on the network interface that can connect to the outside world.
If you would like to pack your project as a war file, then you should first install the environment (application server) like tomcat, glassfish, jboss, etc. After that, you can deploy the war file on the application server.
Likewise, you should install the database server on your host, and edit the spring application.properties to let your spring application connect to the database.

Spring Boot REST Deployment: do we need TomCat?

I've seen Spring Boot Rest project that generates WAR then deployed in a tomcat container. I wonder if this is best practice because I've also read that in Spring Boot, the new final executable JAR file contains embedded server solution like Tomcat too?
Now i've seen a related post that talks about Spring Boot supports both ways but none talked about the pros and cons of each.
Can someone point out the best practice for deploying a spring boot rest project?
I'm thinking of dockerizing the JAR containing embedded server but i'm wondering if there's any drawbacks vs deploying WAR to Tomcat?
A general best practice ( from 12 Factor App ) regarding the application environment and dependencies is "Explicitly declare and isolate dependencies".
A twelve-factor app never relies on implicit existence of system-wide
packages
With that in mind one should gravitate more towards using embedded container as part of explicit dependency instead of a requirement that needs to be fulfilled separately.There are multiple choices for embedded container in the jar artifact (like tomcat, jetty, undertow, netty) and their respective configuration is also extensive, so using these in production environment is recommended ( I have used them a lot). However there might be certain times when you would want to create a war instead, for e.g., a war file will be deployable in any full-fledged EE Application server ( Weblogic, Wildfly etc) which might be mandated by your environment. With a war, your number of options in terms of app server increases. Personally for me, spring boot jar with embedded tomcat has been quite effective. With embedded container option what you need is a virtual machine with OS and Java installed and you are good to go.
However there is a special limitation related to JSP as mentioned here in Spring Boot documentaion which explain a good reason why you might need to package as a war but still run as jar.

Deploy spring boot applications

I know spring boot applications can be deployed to production environments as war files. But what is the typical way of deploying spring boot applications? Does it only require a jvm, not a container?
The Spring Boot Project Page states that Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
Means by default, the Spring Boot maven or gradle plugin builds self-contained executable jars, that contain all dependencies and an embedded webserver, e.g. tomcat or jetty. The Spring Boot Getting Started doc gives you an introduction to that. Using this approach you just need a JVM to run your application. But you can also configure it to create war files if this is a better fit to your production environment.
Does it only require a jvm, not a container?
It can run anywhere Java is setup.
Spring Boot's use of embedded containers and why Spring chose to go the container-less route. Many of their main driving forces were ease of use while testing and debugging, and being able to deploy Spring-based Java applications to the cloud, or any other environment.
Rest can be found out in attached image.
Spring boot applications if they are serving web requests do require a container. You can either deploy them as a war inside a container such as tomcat/jetty. Or you can deploy them with embedded container, tomcat.

How to set up Spring multi maven module using spring boot

I would like to evolve my Spring application with a better architecture. The technologies I'm using are : spring portfolio ( spring mvc, spring test, spring Web, spring core, spring rest...)
Today I'm using packaging to structure the different layers of my application: models, services, api and of course web where I have my controllers.
I would like to know how can I use the power of spring boot to make a multi module maven architecture with an xml spring configuration for a Web application. I read that spring boot have an embedded tomcat and since I'm using eclipse with a separate tomcat server I would like to deploy my application on it and I think that this can create a problem.
I already found some links on github with this type of projects most of them are not elaboring an architecture of a Web application and use a class for spring configuration with the embedded tomcat that spring boot offers.
Thank you
Ps: sorry for my bad English
What you mean by multi module. If you want to build your jar for multiple environment you can use maven profile for it. Spring boot is nothing but a spring project which ease the configurations for you.
Regarding deployment to your own server, you have to convert the jar to war. Read "What about the Java EE Application Server" section of below link.
https://spring.io/blog/2014/03/07/deploying-spring-boot-applications

Spring MVC project as jar

I am new to Spring MVC and I have now come accross tutorials that explain how to deploy your web project as a .jar. My IDE is the Spring Tool Suite. I have always used .war + Apache Tomcat.
Can someone elaborate a bit from the practical point of view why to use .jar instead of .war? Any problems to be aware of?
edit: other answers are welcome too
Spring Boot uses fat JAR packaging where is embeds Servlet container with all dependencies into this single JAR.
If you are using Maven, it uses spring-boot-maven-plugin to package the project.
Practical usage of this approach is simple. Ability to easily run Srvlet based Spring application from command line with externalized properties. Such configuration enables powerfully orchestration possibilities which are often used in modern enterprises in so called Microservices or SOA architecture.
There is group of people out there (including myself) which believe that deploying various WAR files of unrelated applications into single Servlet runtime is not very good idea.
So fat JARs are handy for separate Servlet runtime per application deployment.
About having .jar and Tomcat + .war on the same machine, it is possible and I use this. This may be not cool but I had a .war application running in a tomcat server before the rise up of spring boot. Now my new apps are spring boot apps, and we are migrating our architecture to SOA concept, but we can't change the tire with the moving car. The main application, the WAR is running in a tomcat server and the others (.jar) are self contained ( embedded tomcat ), each one running in a different port. It was the most viable solution available for us by the moment.

Resources