I'm having trouble with the autoconfigurer for Jetty on Spring Boot 1.5.8. I need to use Jetty 8 instead of Jetty 9 for Java 6 compatibility, but the autoconfigurer does not detect the jetty classes:
EmbeddedServletContainerAutoConfiguration.EmbeddedJetty:
Did not match:
- @ConditionalOnClass did not find required class 'org.eclipse.jetty.webapp.WebAppContext' (OnClassCondition)
The dependencies part of my build.gradle:
dependencies {
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.12'
compile 'org.springframework.boot:spring-boot-starter-web', {
exclude module: 'spring-boot-starter-tomcat'
exclude group: 'com.fasterxml.jackson.core'
}
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.7.9' // last version for Java 6
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.7.9'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.9.1'
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
//providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
providedRuntime 'org.springframework.boot:spring-boot-starter-jetty', {
exclude group: 'org.eclipse.jetty'
exclude group: 'org.eclipse.jetty.websocket'
}
def JETTY8_VERSION = '8.1.22.v20160922'
['jetty-server', 'jetty-webapp', 'jetty-servlets', 'jetty-continuation', 'jetty-client',
'jetty-http', 'jetty-util', 'jetty-io', 'jetty-servlet', 'jetty-xml', 'jetty-security'].each {
providedRuntime "org.eclipse.jetty:$it:$JETTY8_VERSION"
}
}
This subsequently results in:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
...
The strange part is, if I declare EmbeddedServletContainerFactoryBean explicitly, it works:
@Bean
EmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() {
try {
def clazz = Class.forName('org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory')
clazz.newInstance()
} catch (NoClassDefFoundError cnfe) {
null
}
}
ext['jetty.version'] = '8.1.22.v20160922'instead what you have now. The same applies to Jacksonext['jackson.version] = '2.7.9'`. - M. Deinumextfrom what I had before was enough for the autoconfigurer to work (though I'm not sure exactly why). If you want to write that up as an answer, I'll accept it. - Artefacto