Using Spring Framework Web when Tomcat is already installed and running - spring

I am studying Spring Framework (all features) preparing to start some microservices and web applications for the first time. I am puzzled by the injection of Tomcat by Spring. If I buy Java hosting with Tomcat already running or set up tomcat to be already configured and supposedly running on a server, is this going to cause a conflict because it is also included in Spring? Or are we talking two different things where what is included in Spring is a connector to Tomcat instead of Tomcat itself?

I believe you are talking about Spring Boot which comes with bundled tomcat (JAR packing). If you package as a JAR, tomcat will be bundled but if you want to use your own tomcat or Jetty or whatever you should look at bundling as WAR file which will exclude tomcat bundling.
few pointers for you
https://spring.io/blog/2014/03/07/deploying-spring-boot-applications
https://therealdanvega.com/blog/2017/06/28/deploying-war-application-server-spring-boot

Related

Vaadin + Spring Boot + Osgi

Does some one already managed to setup a Vaadin (19 to 21) Web application using Spring Boot and Osgi (as bundle) ?
I've managed to have a Vaadin application running under Osgi container (Karaf).
I've managed to have a Spring Boot Application running under Osgi container (Karaf).
But not both at the same time.
In fact, when trying, no route are being registered and FixedVaadinServlet is never called.
Thanks for help.
I have to say that I don't exactly understand your question since Spring is not OSGi compatible (it just has no OSGi manifest) so I don't see how it may work at all.
Now I'm going to guess....
I've managed to have a Vaadin application running under Osgi container (Karaf).
So your application is built as an OSGi bundle and you have deployed it to Karaf (OSGI container) and it works.
I've managed to have a Spring Boot Application running under Osgi container (Karaf).
You have built something (either WAR or a Spring boot Jar) which is a Web application and you have deployed it to Karaf AS A WEB Application.
This feature provided by Karaf : it's not pure OSGi container. It allows to deploy WEB applications to it.
These Web Applications have no any relation to OSGi.
So you have no Spring application which works in OSGi: if you use another OSGi container (which doesn't support extra features like Web app deployment) then you won't be able to use Spring there since as I said Spring is not OSGi compatible.
So I don't see how it's possible to use Spring + OSGi at all.

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.

Does spring boot needs a WAS (Websphere Application Server)?

In my theory spring boot is capable of running java web application stand-alone. It says it has a own embedded servlet container and can use JNDI itself.
I built a war file before (spring-mvc, security, gradle built), but Spring boot assemble jar file and it runs on any machine which has JVM.
So my question is, if I made a spring boot based web app (contained JSP files & JNDI for looking up datasource), although it has own embedded servlet container and packaged jar file for running standalone, do I still need to package it as WAR file and deploy it in WAS (Websphere Application Server) or servlet containers for any reasons such as performance, stability, scaling-out etc?
WAS is an full blown Java Enterprise Application Server, on the other hand you have Spring that only requires a Servlet Container (Servlets are a part of full JEE).
Servlet Containers are for example: Tomcat, Jetty, but also WAS.
Spring Boot is able to package the complete application TOGETHER with the code of Tomcat in an JAR, so that this jar contains the Servlet Container and your Application.
Do I need a additional WAS for performance, stability, scaling-out etc?
Performance: No - There should be no important performance differerence between Tomcat and WAS when you run a Spring-Application. (Only that Tomcat needs less memory for itsself)
Stability: Tomcat and WAS are both very mature products.
Scaling: You can build a cluster of Tomcats by your own.
The main features of WAS over Tomcat are:
- WAS supports EJB and CDI (Tomcat would need TomEE for this), but Spring will not use it, because it is its one Dependency Injection container
- WAS has more Monitoring features, but this does not matter, because Spring Boot has Actuator
#See Difference between an application server and a servlet container? for more details
Simple answer is No. You do not need any Full blown application servers for any of the reasons that you mentioned (for performance, stability, scaling-out). You can just do fine with tomcat
Edit
Looks like you are using only JNDI feature from the Application server. Do you really need JNDI when you pack your servlet container along with your application ? I don't think so. That days are long gone.
JNDI really shines when you have to move an application between
environments: development to integration to test to production. If you
configure each app server to use the same JNDI name, you can have
different databases in each environment and not have to change your
code. You just pick up the WAR file and drop it in the new
environment.https://stackoverflow.com/a/7760768/6785908
(If you still need JNDI to be used to look up your data source refer: https://stackoverflow.com/a/24944671/6785908).
No, still I do not really see a reason for packaging your application as WAR and deploy it to traditional application server. That being said, if you have some existing infrastructure lying around and you are being forced to deploy to existing WAS (or WebLogic or JBoss any application server for that matter) server, then I rest my case :).

Spring Framework hosting

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.

deploy Apache ServiceMix 4 application into JBoss Application Server 7

I have an standalone Apache ServiceMix 4.4 application, it works nicely. Now, I want to deploy this application inside a JBoss Application Server 7. I use Maven as project and dependency management tool.
My objective is deploying the application not touching any line of code, only maven POM files. I can add new dependencies, change some versions (minor) and use different tools. I want, as a second objective, integrate all the Apache CXF DOSGi container features into JBoss AS ones seamlessly.
I think it is possible, but I found information for old releases of JBoss and ServiceMix or incomplete guides like this.
Can someone provide more information about that?
EDIT
I have found some issues in JBoss issue tracker:
Initial runtime support for Karaf based products
And some JBoss forum topics:
Migrating osgi bundles running in Karaf to JBoss 7 as OSGI container
I forgot to mention that my application is using Apache Karaf OSGi runtime.
Well Servicemix is "pre-"setup of a Container (Apache Karaf) and lot's of other Apache Projects like ActiveMq and Camel plus some ServiceMix specialties. So why would you want to deploy this setup in another Container?
If you want to do something like this, try to deploy std. Apache Camel, ActiveMQ and CXF and your own app in JBoss.

Resources