Can I deploy a Spring WebFlux application as a WAR - java

Here
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
I read that "War deployment is not supported for WebFlux applications". Is it only restricted for spring-boot applications or I cant do it at all with spring web flux? Assuming I don't user boot configurations and starters.

You' referring to the Spring Boot documentation here - this limitation only applies to Spring Boot.
You can deploy a Spring WebFlux application (outside of Spring Boot) as a WAR file inside a Servlet 3.1+ container. For that, the Spring Framework reference documentation says:
To deploy as a WAR to any Servlet 3.1+ container, you can extend and
include AbstractReactiveWebInitializer in the WAR. That class wraps an
HttpHandler with ServletHttpHandlerAdapter and registers that as a
Servlet.

Related

Use embedded tomcat instead of netty with spring-gateway

I'm running this project: https://github.com/wdahlenburg/spring-gateway-demo
It uses netty by default, how can I change it to embedded tomcat instead? I've tried to modify the pom.xml and replaces spring-boot-starter-test with spring-boot-starter-tomcat, but it doesn't work.
Does anyone know how to do that?
I don't think it's possible, spring cloud gateway is build on top of reactive Spring WebFlux project and requires netty runtime, as stated in docs:
Spring Cloud Gateway requires the Netty runtime provided by Spring Boot and Spring Webflux. It does not work in a traditional Servlet Container or when built as a WAR.

Spring MVC or Spring Boot for wildfly deployment

I am converting Java web project into Spring Project. (10 JSP and 5 controllers connecting to DB)
We are using Wildfly server for deployment.
Is there any use of creating Spring Boot project (though i have facilities like actuators, starters etc.)
or
Is it fine to create Spring MVC Project and deploy the war in Wildfly as i am not using any container here and spring boot project will be an overhead? Basically i am finding why should i use spring boot here?
it depends.
Spring boot is just SpringMVC + Tomcat in one JAR (very simplified definition, I know).
If you have an existing and working Wildfly Server, use it. Compile your web app as WAR an deploy it. You will have also better configuraiton, server update and server bugfixing possibilities. At least that was in my case, as my team mates had a lot of experience with Wildfly.
We are using SpringBoot for small pure REST (micro)services (without HTML, JSP), since they are fast to implement and to deploy (just run a jar file). All of these applications have their own Tomcat server - with own PORT. If you want a new Tomcat version you have to recompile your application. This could be a disadvantage (but not realy).

Embed Grizzly (glassfish) Servlet Container with Spring Boot Java

Spring boot by default uses Tomcat as an Internal Embedded Servlet Container .
It has also got support for Jetty and UnderTow.
I have build a Restful Application using spring boot . But now i need to deploy it on Grizzly (Glassfish) Servlet Container .
How do i embed my application to run on grizzly as spring dosen't have support for the same.
https://github.com/spring-projects/spring-boot/issues/5015.
Please help as i researched a lot on thistopic but i coudnt get any link that shows how to embed a new Servlet Container for our spring boot app that spring dosent have support for.
Thanks
The Grizzly website states that Grizzly's servlet support is incomplete:
This is not a Servlet compliant implementation and as such, not all features exposed by a typical Servlet container are available here.
I haven't seen anywhere that expands on what those missing features are, but there's a good chance that what you're trying to do isn't possible without filling in some gaps in Grizzly's servlet support.
Assuming that it is possible, you need to write Grizzly-specific implementations of Spring Boot's EmbeddedServletContainerFactory and EmbeddedServletContainer interfaces. This is a fairly significant amount of work so, before undertaking it, I would ask yourself what you will gain by being able to use Grizzly as an embedded servlet container versus using Jetty, Tomcat, or Undertow which are already supported out of the box.
If you do decide to tackle this, reading the source code for the existing implementations for Jetty, Tomcat, and Undertow is the best way to learn about what needs to be done:
JettyEmbeddedServletContainer.java
JettyEmbeddedServletContainerFactory.java
TomcatEmbeddedServletContainer.java
TomcatEmbeddedServletContainerFactory.java
UndertowEmbeddedServletContainer.java
UndertowEmbeddedServletContainerFactory.java
As pointed by #Andy there is no support for Spring Boot and Grizzly .
Finally i moved to Spring MVC for the same.
Here is the working repo where i embedd Spring MVC with grizzly.
Hope it helps someone.
Link
There is now a third-party implementation of a Spring Boot starter for Grizzly which has specific implementations of the Spring Boot's EmbeddedServletContainerFactory and EmbeddedServletContainer classes for Grizzly.
Besides that it also offers JSP support through Tomcat's Jasper JSP engine, simply by specifying an additional dependency. You can find the project at GitHub and it is also listed in the Spring Boot starters list.

Is there a deployment deliverable(ear/war) for a web application running in Spring Tool Suite(STS)?

I have a web application created using Spring boot and I am using Spring Tool Suite(STS) for developing it. If my understanding is correct, tomcat is internally embedded in STS and I can run/debug the application from STS with the help of Application.java.
Now my doubts are, when we run the application by running a java class as 'Spring Boot App'
What is the deployment deliverable?(ear/war)
Where exactly the deliverable getting deployed? I have searched
everywhere in STS directories and could find it
If there is nothing like this, then how is it working?
Do this make sense or am I wrong with my understanding?
Your understanding about Spring Boot is wrong.
The embedded Tomcat is included on your application, when you use Spring Boot.
Spring Boot generates a .jar file. When the application is started, Spring knows how to bootstrap a Tomcat instance for you
If you are using the "Run" command on STS, there is no deliverable yet. The main method on Application.java has everything that is need for Spring run your application
Spring Boot is a project dedicated to create stand-alone Spring applications. As I said on first item, Spring Boot knows everything that is need to bootstrap a new Tomcat instance and run your application. You don't need an application server when working with Spring Boot, Spring provides by a embed Tomcat/Jetty or Undertow. The Tomcat is INSIDE your application with your code, not an external application server.

Is it mandatory to integrate RESTEasy with Spring on JBOSS AS?

I am trying to expose a simple web resource on JBOSS AS using Spring.
Is it mandatory to configure RESTEasy with Spring in order to the server to serve the requests correctly?
I have already deployed my war file without no configuration in the web.xml and I don't know if the configuration has something to do with RESTEasy integration.
All the documentation found indicates so but I need to be sure if it can't be done without RESTEasy.
If you want to access Spring beans in your REST endpoint classes, then you have to integrate Spring with RestEasy, so that RestEasy is able to find your Spring beans. If you don't have this requirement, then it's not necessary.

Categories