Spring boot application with Embedded tomcat

I am working on a project, we are using Spring-Boot, STS. I just start the project by right clicking on the main file and run it as a spring boot app and it just starts. Now I am asked to run it from Embedded tomcat on another machine like Amazon EC2 instance. In a normal spring project that I used, create a war file, put it in tomcat-> webapps folder and run it from bin. In case of embedded tomcat, how can I run the application without tomcat. where is my war (which includes the built-in tomcat dependencies)? Please suggest some kind of solution, this is the first time you work with spring boot and embedded tomcat. Appreciate your suggestion.

+3


source to share


3 answers


It is recommended that you create a jar file for your spring boot application. This vessel contains an embedded tomcat inside it. But of course you can build it as a war file. To run them you can simply run java -jar your-jar-file.jar

orjava -jar your-war-file.war



+4


source


Just inject the spring tomcat starter, inside your pom or gradle build. This will bring all tomcat dependencies to your application jar. The built-in tomcat tool, at runtime inside your Spring Boot JVM, starts a server with dependencies in your jar. This way, all issues related to war progression to tomcat folder and restart are eliminated. Build your jar using the Spring Boot plugin. mvn spring-boot: run or gradle bootRun and then just run that jar like any executable jar.

java -jar your-app.jar

      



This calls the Spring Boot Main class. Which internally starts your server and creates the context for your application. This works for the whole platform, your local or EC2.

+3


source


First, let me clarify about war

and jar

in the context of modern java web application development.

In the distant past, applications were written, packaged into files, .war

and deployed to servers tomcat

that ran on some operating systems such as Linux. Typically these applications were large and reflected all the business logic of some service

, like a library site, which depended entirely on that one application to process the requests, generating a suitable response for each one.

Over time, the network has become larger: More users + more data + stronger computers = more traffic

. It was difficult to maintain this application development model because it was unable to reliably handle high-performance traffic.

It's like Microservices . Long story short: In Java, the best way to create microservices is to use spring-boot

, and the best way to deploy microservices is to use an embedded server for each microservice, for example tomcat

. These microservices are then ideally deployed in the cloud (for example AWS

). Cloud services know how to deal with jars

because banks are native to them.

Now, to your question, where will your war be? Your war won't work. Your jar will be run by a cloud service and because it has a built-in tomcat dependency. It will start tomcat, which will listen on the default port 8080

. This will be the gateway for your application that you created. The cloud service will probably allocate the application to DNS

your application and you will be able to communicate with this built-in tomcat

that way.

0


source







All Articles