spring-boot:从Maven命令行执行时的响应压缩 [英] spring-boot: response compression while executed from Maven command line

查看:126
本文介绍了spring-boot:从Maven命令行执行时的响应压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣为基于Java 8/spring-boot 1.3.2/Maven 3.3的应用程序启用HTTP响应压缩.

I'm interested in enabling HTTP response compression for my Java 8 / spring-boot 1.3.2 / Maven 3.3 based application.

遵循

Following the spring-boot reference documentation from http://docs.spring.io/spring-boot/docs/1.3.x/reference/htmlsingle/#how-to-enable-http-response-compression, I have added the following change to my application.properties:

server.compression.enabled = true

server.compression.enabled=true

尽管在上述添加之前应用程序已成功启动,但使用以下Maven命令时,应用程序无法启动并显示以下错误:

While the application started successfully before the above addition, with it the application fails to start with the following error when using the Maven command below:

mvn clean spring-boot:run
...
...
2016-01-26 09:48:48.802 ERROR 15204 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.IllegalStateException: Compression is enabled, but GzipHandler is not on the classpath
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at com.miletwentyfour.client.Application.main(Application.java:43) [classes/:na]
Caused by: java.lang.IllegalStateException: Compression is enabled, but GzipHandler is not on the classpath
    at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory.createGzipHandler(JettyEmbeddedServletContainerFactory.java:192) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory.addHandlerWrappers(JettyEmbeddedServletContainerFactory.java:168) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory.getEmbeddedServletContainer(JettyEmbeddedServletContainerFactory.java:148) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:160) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
    ... 8 common frames omitted

根据参考文档部分64.18.2,我的下一步是将以下依赖项添加到pom.xml:

My next step, per the reference documentation section 64.18.2, was to add the following dependency to the pom.xml:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-servlets</artifactId>
    <version>9.3.7.v20160115</version>
</dependency>

使用mvn:dependency:tree我可以验证是否在应用程序中包含了jetty-servlet作为编译时范围内的依赖关系.但是,应用程序无法以与上面相同的错误输出启动.

Using mvn:dependency:tree I can verify that jetty-servlets is included in the application as a compile time scoped dependency. Yet, the application fails to start with the same error output as above.

从Maven命令行启动应用程序时,谁能指出我所缺少的内容和/或需要做些什么才能使响应压缩成功工作?

Can anyone please point out what I am missing and/or what do I need to do to get response compression to work successfully when launching the application from a Maven command line?

推荐答案

安迪·威尔金森(Andy Wilkinson)是正确的,并提供了我所缺少的必要信息.

Andy Wilkinson was correct and provided the needed information I was missing.

为了他人的利益,我将Spring Boot 1.3与9.jet版本的9.jet版本混合在一起.一旦使用了最新版的spring-jetty9. 2 .x-我使用了9.2.14.v20151106-我的应用程序正常启动.

For the benefit of others, I was mixing Spring Boot 1.3 with the 9.3.x flavors of spring-jetty. Once I used the latest of spring-jetty 9.2.x -- I used 9.2.14.v20151106 -- my application started as normal.

总结一下,这里是我所做的更改:

To summarize, here the changes I made:

application.properties:

application.properties:

server.compression.enabled=true

pom.xml:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-servlets</artifactId>
    <version>9.2.14.v20151106</version>
</dependency>

这篇关于spring-boot:从Maven命令行执行时的响应压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆