How it works...

The reason that this works is because of Spring Boot's autoconfiguration magic. We had to remove the Tomcat dependency from the build file in order to prevent a dependency collision between Tomcat and Jetty. Spring Boot does a conditional scan of the classes in the classpath and depending on what it detects, it determines which servlet container will be used.

If we look in the ServletWebServerFactoryAutoConfiguration class, we will see the following conditional code that checks this:

/** 
 * Nested configuration if Jetty is being used. 
 */ 
@Configuration 
@ConditionalOnClass({ Servlet.class, Server.class, Loader.class}) 
@ConditionalOnMissingBean(value = ServletWebServerFactory.class,  
search = SearchStrategy.CURRENT) public static class EmbeddedJetty { @Bean public JettyServletWebServerFactory
JettyServletWebServerFactory() {
return new JettyServletWebServerFactory();
} }

The @ConditionalOnClass annotation tells Spring Boot to use only the EmbeddedJetty configuration if the classes of Jetty, namely org.eclipse.jetty.server.Server and org.eclipse.jetty.util.Loader, are present in the classpath.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.110.119