I am creating an application with websockets where I use Spring's autoconfiguration ability via the #EnableAutoConfiguration annotation before my main class. I am attempting to use Tomcat because that is what I am familiar with. I am using apache camel to route my messages and the camel dependencies have a lot of jetty jars in them.
The jetty jars are forcing the autoconfiguration in spring to start a jetty instance rather than a tomcat one and I was wondering if there was any way to add parameters or anything else to the autoconfiguration annotation that would ensure it worked how I needed and started the Tomcat instance regardless of the jars in my dependencies. I tried excluding all of the jetty jars, but it still wouldn't revert to Tomcat like it was before I added the back end camel to my application.
Any advice? Thanks in advance for the assistance.
Related
I have a SpringBoot2-Application configured as a war package that I want to run on the command-line but also be deployable in an application server.
Per the instructions, I configured the dependency to the embedded Tomcat to scope "provided" and also added a TomcatServletWebServerFactory to override the initialization of the embedded Tomcat so that I can enable jndi.naming because I want the datasource to be read from the jndi of the application server. In case I start the application standalone, I provide the jndi-resource by adding it to the embedded Tomcat during start.
This fails nicely: if the scope is "provided" and starting standalone, my TomcatServletWebServerFactory is not run and jndi is not activated so the lookup of the datasource fails. But that package works fine in Wildfly. If I remove "provided", the standalone application starts fine but it crashes in Wildfly out of obvious reasons (there is a Tomcat instance started to many that can not be cast to an Undertow-instance).
Has anybody else experienced this and has a solution? What does the SpringBoot-Maven plugin do to "hide" an embedded Tomcat in a war? Maybe my TomcatServletWebServerFactory has to adjust to the "provided"(hidden) configuration?
Thanks for all suggestions.
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.
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.
Normally, when you developing a simple mvc application, with maven, based on Spring Boot, you starts from SpringApplication.run(.class, args), then endpoint that returns you e.g. "Hello World". After that you write mvn spring-boot:run (or start it by your ide) and Spring makes everything for you.
Spring also setting up Tomcat servlet container, and then deploy your package to that, so you don't need to make it manually.
And my question:
How exactly Spring starts that Tomcat service? If i would like to start in same way some other services e.g. Apache Felix, Apache Jackrabbit or some other, what should I do? Is that any configured bean that is set in starter package, or some other mechanism?
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/>.