Embedded Jetty Spring MVC - java

I want to embed jetty in one of my spring mvc application. I followed the tutorial http://examples.javacodegeeks.com/enterprise-java/jetty/jetty-tutorial-beginners/ (scroll down to embedded jetty part i.e 2.0).
I followed and understood the tutorial but it seems to be working for servlets only whereas in my application I'm having controller methods.
Server server = new Server(7070);
ServletContextHandler handler = new ServletContextHandler(server, "/example");
handler.addServlet(ExampleServlet.class, "/");
server.start();
This code seems to add only a servlet (ExampleServlet.class) in embedded jetty but I want to make it work for my spring mvc application where I'm using #RequestMapping etc for URL information. The question is how to add those controllers in the embedded context handlers. Please let me know what all changes I need to do to embed jetty in my spring mvc application and following most of the part of this tutorial http://examples.javacodegeeks.com/enterprise-java/jetty/jetty-tutorial-beginners/ (scroll down to embedded jetty part)

Manual embedding is obsolete; use Spring Boot instead, which handles all of this for you. Boot offers out-of-the-box starters for Tomcat, Jetty, or Undertow.

Related

Tomcat application to spring boot application

we have old tomcat application in our project. I like to change it to spring boot for easing my development. but I don't know the way. Will someone helps me out, how to do that
Actually they are two different things.
You can have a Tomcat server with Spring Boot framework.
If you want to get this server setted with Spring Boot, just get a look in this link:
https://www.baeldung.com/spring-boot-configure-tomcat

Keeping Web.xml in a migrated application from struts2 application to Spring boot

So, I'm trying to migrate a simple struts2 application into spring boot, and I already achieved that by registring the StrutsPrepareAndExecuteFilter as a bean in my Application.java
The problem is that my client wants to migrate a web application from JAVA EE to Spring boot while keeping web.xml because it has many servlets, filters and listeners, and he doesnt want to register them as beans.
So I'm trying to figure out if there is a way to use web.xml configuration in a spring boot application, I have already spent two days googling about that but still no luck..

Does Spring Boot support servlet 2.5 auto-configuration?

I would like to create a Spring Boot application to be deployed on Google AppEngine infrastructure. GAE currently only supports servlet 2.5 web applications.
Is it possible to use Spring Boot - using auto-configuration - in combination with a old-fashioned web.xml?
Can I for example use a contextClass/contextConfigLocation pointing to a #Configration class including #EnableAutoConfiguration?
All Spring Boot examples seem to use a simple Application class with main method to run the application. So I would like to know if Spring Boot supports using a web.xml as start point to boot the application?
More than one question there:
There's nothing stopping you from using web.xml (it's still part of the Servlet spec). Most people prefer the Java initializers these days.
#EnableAutoConfiguration works for any application context (it just uses features of Spring).
But Spring Boot out of the box doesn't have a ContextLoaderListener that knows about SpringApplication, so you miss some of the benefits of Boot if you do as you describe. There's one you might find useful here.
Spring Boot Actuator relies on a few Servlet 3.0 features here and there so you need workarounds for a 2.5 environment (see this spring-boot-legacy prototype for details).
There's a sample app here that runs on GAE, currently deployed here: http://dsyerboot.appspot.com/.

Using spring core functionalities in tomcat based jersey application

I want to use spring's dependency injection for now(other core functionalites later maybe) in tomcat application.
I want to set up spring 2.5.5 in tomcat7, But don't have clarity on how to do this.
Specifically I am confused because I don't know whether to use Spring MVC or use just spring in tomcat.
I found this question helpful: Tomcat with Spring, But still didn't get the whole scenario on how to setup tomcat with spring.
You can do either, using just core spring with tomcat is fine. MVC provides additional functionality.
Take a look at the spring source examples on github, and read their docs.
(BTW I thouroughy spring-MVC component - it really saves time developing webapps)

Embedded Jetty and Spring Web MVC

For a pet project I would like to have an embedded Jetty run a Spring Web MVC app. I've used Spring in web containers (where it's easy to tell "where to start") and I've used embedded Jetty without Spring.
It feels a bit like the chicken or the egg problem if I want both to work together. What is the best way to organize the project? In other words, what shall I put in main()? Should it be a Spring app that happens to have Jetty as a bean (what about contexts then?)? Or should I start Jetty alone and plug Spring in via servlet listener? What are the caveats?
Jetty in a Spring container is used to start webapp, springified or not. The webapp and your webapp don't have the same Spring context without tricks.
So, you have to create a Jetty server in your main, add your webapp and start the server. The best way is using a web.xml like a common Java EE server, and add this descriptor to your Jetty server.
I think it is more reasonable to start Jetty alone and plug Spring in via servlet listener in web.xml. Let Spring manager all the app specific beans and let jetty focus on running your app, and maybe some day you can deploy you app to antoher servlet container without changing anything.
This is one way to embed Jetty in Spring
http://www.springbyexample.org/examples/embedded-spring-web-services.html

Categories

Resources