Spring boot - unable to use web.xml with WAR deployment - spring

I am not able to use web.xml with spring boot in war deployment.
I am aware that there are ways of converting web.xml using #Configuration, but I must stick with web.xml for now. I was following the official document, here: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-create-a-deployable-war-file-for-older-containers
I was able to deploy my application in WAR file, but it was not using web.xml.
Maybe I am not following the step 85.2 correctly, as I am not sure what it means by "load an applicationContext via a DispatcherServlet":
85.2 Create a deployable war file for older servlet containers
Older Servlet containers don’t have support for the
ServletContextInitializer bootstrap process used in Servlet 3.0. You
can still use Spring and Spring Boot in these containers but you are
going to need to add a web.xml to your application and configure it to
load an ApplicationContext via a DispatcherServlet.
Can you guide me or point me to any examples or working sample project using web.xml in spring boot? I am using weblogic server.

Related

Force Spring Boot to use servlet mapping in web.xml

I'm currently trying to shift my existing dynamic web project to Spring boot project and it uses web.xml for servlet mapping. I understand that spring would ignore the web.xml file, what should be the correct approach for spring to use the existing web.xml? And yes, I still need to stick to using web.xml for this project.
I'm kinda new to this, please guide me through! Thanks!
I suppose that you need to stick with a web.xml because your container uses an older version of Servlet than 3.0.
Spring Boot is built on Servlet 3.0. You have to update your main class to extend SpringBootServletInitializer and override configure method, which tells spring to use its Servlet 3.0 support. Embedded containers like Tomcat need Servlet 3.0, so if you want to start your project during the development process (including JUnit tests) in embedded containers, I think, from what I know, the only way is to rewrite your web.xml to Servlet 3.0 java config. But if you really want to deploy you app in an older container, you still can by using spring-boot-legacy module. It allows you to use web.xml for older containers; only thing you have to do is to add
org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener in your web.xml.
For more information about deploying war in an old container, take a look at Spring Boot's official documentation.
Spring Boot uses Servlet 3.0 APIs to initialize the ServletContext
(register Servlets etc.) so you can’t use the same application out of
the box in a Servlet 2.5 container. It is however possible to run a
Spring Boot application on an older container with some special tools.
If you include org.springframework.boot:spring-boot-legacy as a
dependency (maintained separately to the core of Spring Boot and
currently available at 1.0.2.RELEASE), all you should need to do is
create a web.xml and declare a context listener to create the
application context and your filters and servlets.
This is a very old question, but I'm currently on the same situation and I will share my experience.
I extended the SpringBootServletInitializer class to create my #SpringBootApplication, and it will INCLUDE your web.xml configuration by default. I'm still able to declare or edit existing servlet mapping, and it will be taken in account.

Deploy a war file inside the embedded servlet container in a Spring Boot web application

I want to deploy one or more already existing war files into the embedded servlet container in the Spring Boot project.
Specifically, I want to fire up both the hawtio and the ActiveMQ Web Console wars inside the same application, in addition to some of my own stuff.
Is there a correct way to do this, or do I have to go for the "nuclear option" of configuring the servlet container instance myself? (Note that I'd rather have Jetty than Tomcat, but if it is one line with Tomcat, and lots of cruft with Jetty, then Tomcat is okay)

Migrating an existing spring jersey servlet2.5, Jersey2.3 webapp to springboot

Evaluating to port an existing mid to large sized multi module JEE application, this consists servlet 2.5, Jersey for rest and Spring 3.2.9 (JDK8, Maven 3. currently we build a war file and deploy it on to aws. My objective for this exercise is to be able to use spring-boot to create a self contained executable jar that can be installed on AWS and this would help us just run on cloud with java -jar
Is it possible to use spring boot considering the project is not using spring-web module, it is more traditional Servlet2.5 statically declaring all servlets and filters in web.xml
which approach is better, adding spring boot as a parent or dependency.
Any experience and info our senior spring community members have in this kind of migration.
This is absolutely possible to do even if you're not using Spring Web MVC.
You can use spring-boot-starter-parent like a BOM POM, so you can import its dependencies without having to change your POM's parent.
Take a look at the Spring Boot documentation for migrating a web.xml application to Spring Boot. The main points here for traditionally deployed servlets and filters are:
A #Bean of type Servlet or ServletRegistrationBean installs that bean
in the container as if it was a <servlet/> and <servlet-mapping/> in
web.xml.
A #Bean of type Filter or FilterRegistrationBean behaves
similarly (like a <filter/> and <filter-mapping/>.

Tomcats RemoteIPValve not invoked in Spring Boot Application deployed as a WAR file

My Spring Boot 1.3.2 Application is deployed as a WAR file into a standalone tomcat7. I am trying to activate the RemoteIPValve using server.use-forward-headers=true as described in the spring boot docs.
But the RemoteIPValve is not properly configured nor invoked when handling the request. Log says:
NonEmbeddedServletContainerFactory detected.
When I start the application using the maven plugin I get a:
Initializing Spring embedded WebApplicationContext
... and RemoteIPValve is working as expected. How can I accomplish the same using WAR File deployment?
When you deploy a Spring Boot application to standalone Tomcat, none of the embedded server configuration takes effect. Instead, you need to update your Tomcat installation's configuration to enable the valve. To use the valve in its default configuration, add the following to server.xml:
<Valve className="org.apache.catalina.valves.RemoteIpValve"/>

Deploy a spring boot war to websphere 7.5

I have a Spring boot war(ReESTful webservice with Spring) built using a gradle build. Initially I built an executable jar and then converted into war. But I am not able to deploy this on websphere 7.5 app server. It can be deployed on Websphere 8.0. I read that spring boot war built without having web.xml is only supported in WAS 8 or above. How can i convert this to a war file that can be deployed on WAS 7.5?
I read that I need to add a web.xml to the war, but what what should be the content of the web.xml so that it can load all the controllers?
Spring Boot doesn't support Servlet 2.5 officially, but it doesn't take a lot to make it work. You might find this useful: https://github.com/scratches/spring-boot-legacy.
You can get more information at the official documantation.

Resources