Spring Boot Webflux 中的 Unix 域套接字配置
Unix Domain Socket configuration in Spring Boot Webflux
Spring启动版本:2.4.0
Reactor netty现在支持初始化服务器时Unix Domain Sockets。
我正在尝试自定义 Spring 启动 HttpServer
以使用 unix 域套接字而不是使用
的 http 端口
@Configuration
public class NettyConfig {
@Bean
public NettyReactiveWebServerFactory factory() {
NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
factory.setServerCustomizers(Collections.singletonList(new NettyServerCustomizer() {
@Override
public HttpServer apply(HttpServer httpServer) {
return httpServer.bindAddress(() -> new DomainSocketAddress("/tmp/test.sock"));
}
}));
return factory;
}
}
但是应用程序无法使用给定的堆栈跟踪启动:
13:05:36.706 ERROR [restartedMain] SpringApplication.reportFailure:856 : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is java.lang.UnsupportedOperationException
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
at org.springframework.context.support.DefaultLifecycleProcessor.access0(DefaultLifecycleProcessor.java:54)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:942)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:591)
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:63)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
at com.avis.biverve.EntryPoint.main(EntryPoint.java:25)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.UnsupportedOperationException
at reactor.netty.DisposableServer.port(DisposableServer.java:69)
at org.springframework.boot.web.embedded.netty.NettyWebServer.getPort(NettyWebServer.java:193)
at org.springframework.boot.web.embedded.netty.NettyWebServer.start(NettyWebServer.java:109)
at org.springframework.boot.web.reactive.context.WebServerManager.start(WebServerManager.java:54)
at org.springframework.boot.web.reactive.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:40)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
... 20 more
此问题已在 Spring 引导版本 2.4.2
中修复
Spring启动版本:2.4.0
Reactor netty现在支持初始化服务器时Unix Domain Sockets。
我正在尝试自定义 Spring 启动 HttpServer
以使用 unix 域套接字而不是使用
@Configuration
public class NettyConfig {
@Bean
public NettyReactiveWebServerFactory factory() {
NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
factory.setServerCustomizers(Collections.singletonList(new NettyServerCustomizer() {
@Override
public HttpServer apply(HttpServer httpServer) {
return httpServer.bindAddress(() -> new DomainSocketAddress("/tmp/test.sock"));
}
}));
return factory;
}
}
但是应用程序无法使用给定的堆栈跟踪启动:
13:05:36.706 ERROR [restartedMain] SpringApplication.reportFailure:856 : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is java.lang.UnsupportedOperationException
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
at org.springframework.context.support.DefaultLifecycleProcessor.access0(DefaultLifecycleProcessor.java:54)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:942)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:591)
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:63)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
at com.avis.biverve.EntryPoint.main(EntryPoint.java:25)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.UnsupportedOperationException
at reactor.netty.DisposableServer.port(DisposableServer.java:69)
at org.springframework.boot.web.embedded.netty.NettyWebServer.getPort(NettyWebServer.java:193)
at org.springframework.boot.web.embedded.netty.NettyWebServer.start(NettyWebServer.java:109)
at org.springframework.boot.web.reactive.context.WebServerManager.start(WebServerManager.java:54)
at org.springframework.boot.web.reactive.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:40)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
... 20 more
此问题已在 Spring 引导版本 2.4.2
中修复