SpringCloud / spring-cloud-code

🔥《重新定义Spring Cloud实战》实体书对应源码,欢迎大家Star点赞收藏
Apache License 2.0
1.89k stars 1k forks source link

gateway中HTTPS的使用技巧 #45

Closed kimmy-wang closed 4 years ago

kimmy-wang commented 4 years ago

启动报错

org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is java.lang.IllegalStateException: java.lang.IllegalStateException: org.springframework.boot.web.server.WebServerException: Could not load key store 'classpath:samples.jks'
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:81) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.1.16.RELEASE.jar:5.1.16.RELEASE]
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at com.upcwangying.cloud.samples.gateway.SamplesGatewayApplication.main(SamplesGatewayApplication.java:44) [classes/:na]
Caused by: java.lang.IllegalStateException: java.lang.IllegalStateException: org.springframework.boot.web.server.WebServerException: Could not load key store 'classpath:samples.jks'
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.apply(SslServerCustomizer.java:85) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory.createHttpServer(NettyReactiveWebServerFactory.java:137) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory.getWebServer(NettyReactiveWebServerFactory.java:63) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext$ServerManager.<init>(ReactiveWebServerApplicationContext.java:196) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext$ServerManager.get(ReactiveWebServerApplicationContext.java:213) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:88) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:78) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    ... 8 common frames omitted
Caused by: java.lang.IllegalStateException: org.springframework.boot.web.server.WebServerException: Could not load key store 'classpath:samples.jks'
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.getKeyManagerFactory(SslServerCustomizer.java:123) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.getContextBuilder(SslServerCustomizer.java:90) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.lambda$apply$0(SslServerCustomizer.java:78) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at reactor.netty.http.server.HttpServerSecure.<init>(HttpServerSecure.java:37) ~[reactor-netty-0.8.19.RELEASE.jar:0.8.19.RELEASE]
    at reactor.netty.http.server.HttpServer.secure(HttpServer.java:447) ~[reactor-netty-0.8.19.RELEASE.jar:0.8.19.RELEASE]
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.apply(SslServerCustomizer.java:77) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    ... 14 common frames omitted
Caused by: org.springframework.boot.web.server.WebServerException: Could not load key store 'classpath:samples.jks'
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.loadStore(SslServerCustomizer.java:177) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.loadKeyStore(SslServerCustomizer.java:158) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.getKeyStore(SslServerCustomizer.java:131) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.getKeyManagerFactory(SslServerCustomizer.java:109) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    ... 19 common frames omitted
Caused by: java.io.FileNotFoundException: class path resource [samples.jks] cannot be resolved to URL because it does not exist
    at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:137) ~[spring-core-5.1.16.RELEASE.jar:5.1.16.RELEASE]
    at org.springframework.boot.web.embedded.netty.SslServerCustomizer.loadStore(SslServerCustomizer.java:172) ~[spring-boot-2.1.15.RELEASE.jar:2.1.15.RELEASE]
    ... 22 common frames omitted
SoftwareKing commented 4 years ago

@upcwangying Spring Boot和Spring Cloud版本请书中的版本保持一致,你现在的Spring Boot版本是Spring Boot 2.1.15,写这本书的时候,这个版本都还没出现。不是书中的版本,需要自己踩坑解决了。

kimmy-wang commented 4 years ago

@SoftwareKing 建议做一个G版本适配