我在Spring Boot 1.5.8上使用Jetty的autoconfigurer时遇到了麻烦。 我需要使用Jetty 8而不是Jetty 9来兼容Java 6,但自动配置器不能检测码头类:
EmbeddedServletContainerAutoConfiguration.EmbeddedJetty: Did not match: - @ConditionalOnClass did not find required class 'org.eclipse.jetty.webapp.WebAppContext' (OnClassCondition)我的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" } }这随后导致:
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) ...奇怪的是,如果我明确声明EmbeddedServletContainerFactoryBean ,它的工作原理是:
@Bean EmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() { try { def clazz = Class.forName('org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory') clazz.newInstance() } catch (NoClassDefFoundError cnfe) { null } }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 } }最满意答案
默认情况下,Spring Boot 1.5 需要运行Java 7或更高版本。 但是,可以在Java 6上运行Spring Boot 1.5,这在参考指南中有很好的记录。
在你的情况下,你只是在指定所需的Jetty版本时过度思考。
ext['jetty.version'] = '8.1.22.v20160922' 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-jetty', { exclude group: 'org.eclipse.jetty.websocket' } }这样Spring Boot将包含正确的版本,你不需要自己包含它们。
By default Spring Boot 1.5 requires Java 7 or higher to run. However it is possible to run Spring Boot 1.5 on Java 6 and that is quite nicely documented in the reference guide.
In your case you are overthink things it is as simply as specifying the desired Jetty version.
ext['jetty.version'] = '8.1.22.v20160922' 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-jetty', { exclude group: 'org.eclipse.jetty.websocket' } }This way Spring Boot will include the proper versions and you don't need to include them yourself.
更多推荐
发布评论