Vaadin + Spring Boot + Osgi - spring-boot

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.

Related

Spring Boot App - Reference external code during runtime that isn't part of the bundled WAR?

I have a Spring Boot+React application that is packaged as a bundled WAR.
This works well for most cases, but we need to be able to drop-in functionality in some cases that is not part of the bundle (such as via a JAR).
I knew OSGI exists for this case, but not sure of any usage with Spring Boot. Is there another way to do this as well?
If your use case is a kind of small plugin functionality for your spring boot app then you could start an OSGi framework inside spring boot and load bundles from a separate directory. You plugins could then offer their service via an interface that is provided by the spring boot app and an OSGi service with that interface.
You need some good OSGi knowledge for this to work.

Using Spring Framework Web when Tomcat is already installed and running

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

Spring application context in multiple tomcats

If there are multiple web applications in different tomcats, how to configure same application context for all the tomcats
I am not sure if i understand the question correctly. I guess you misunderstand some concepts. First, what is your package; is it war or jar. Do you use Spring MVC or Spring Boot (If you are new i suggest you to use Spring Boot). If you are using Spring MVC you are required to deploy your war to a servlet container like Tomcat. And if you want to deploy your applications to multiple tomcats, it is possible of course. However each application run on their own application context. These application contexts will have same beans and will be on same state when they are firstly initialized. As far as i know it is not possible to share one application context over multiple spring mvc applications and i think it doesn't make sense.
If you are using Spring Boot, your application will run on JVM with an embedded servlet container. In this case, your application is packaged in a JAR file with servlet container and you are not required to deploy the application. When you run the application both servlet container and your application context is initialized. In this situation, you can run multiple applications and as i said before these applications will have different application contexts.

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.

difference between WAB and WAR

I am a newbie to this and read about WABs , but wish to clear the basic difference -
I mean using osgi embedded in tomcat and making a WAR vs making a WAB ?
When should one consider each option ?
1) OSGI embedded in tomcat
2) tomcat in OSGI
3) using a WAB
OSGi embedded in a container (not only Tomcat!) is likely the only option when you are forced to a traditional JavaEE WAR deployment model, i.e. an IT department operates the container and you can only deloy WAR files to it. This bootstraps a whole OSGi framework within the web application and allows modular development within the web application. The web application is then composed as a set of OSGi bundles. It can also be used to migrate/transfer an existing legacy web application into OSGi modules. However, this will be challenging.
I'd like to call the second approach (Tomcat in OSGi) as a pure OSGi approach. Tomcat or any other Servlet container (eg., Jetty) can be deployed as a bundle (or a set of bundles) in an OSGi framework. The OSGi framework is the container. You don't have the full separation of a web application anymore. The can intersect. Some bundles/modules may implement web functionality and others may not. Core functionality (core bundles) can be reused by other web bundles.
The third option is a result of new spec work in OSGi. Basically, it's a web application with an OSGi bundle manifest. Thus, the whole web application can be deployed as a single OSGi bundle on any framework with WAB support. Technically, the bundle may be deployed as a web application to a Servlet container. But it gets access to a BundleContext. This allows the web application to inter-operate with other bundles or web applications running in the same framework.

Resources