springboot dubbo多模块中2个模块都既是提供者又是消费者,第二个启动会报错Address already in use: bind 20880
错误的配置xml
具体报错如下:
com.alibaba.dubbo.rpc.RpcException: Fail to start server(url: dubbo://172.16.1.112:20880/com.example.dubboapi.service.AService?anyhost=true&application=dubbo&bind.ip=172.16.1.112&bind.port=20880&channel.readonly.sent=true&codec=dubbo&dubbo=2.6.0&generic=false&heartbeat=60000&interface=com.example.dubboapi.service.AService&methods=sayA&pid=63756&side=provider×tamp=1561975401431) Failed to bind NettyServer on /172.16.1.112:20880, cause: Failed to bind to: /0.0.0.0:20880
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.createServer(DubboProtocol.java:277) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.openServer(DubboProtocol.java:254) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.export(DubboProtocol.java:241) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:68) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:93) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.registry.integration.RegistryProtocol.doLocalExport(RegistryProtocol.java:181) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:121) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:66) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:91) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:505) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:357) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:316) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:215) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:121) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:50) ~[dubbo-2.6.0.jar:2.6.0]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:888) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at com.example.dubboa.DubboaApplication.main(DubboaApplication.java:16) [classes/:na]
Caused by: com.alibaba.dubbo.remoting.RemotingException: Failed to bind NettyServer on /172.16.1.112:20880, cause: Failed to bind to: /0.0.0.0:20880
at com.alibaba.dubbo.remoting.transport.AbstractServer.(AbstractServer.java:68) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.remoting.transport.netty.NettyServer.(NettyServer.java:61) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.remoting.transport.netty.NettyTransporter.bind(NettyTransporter.java:31) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.remoting.Transporter$Adaptive.bind(Transporter$Adaptive.java) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.remoting.Transporters.bind(Transporters.java:56) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchanger.bind(HeaderExchanger.java:42) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.remoting.exchange.Exchangers.bind(Exchangers.java:70) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.createServer(DubboProtocol.java:275) ~[dubbo-2.6.0.jar:2.6.0]
... 31 common frames omitted
Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:20880
at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:303) ~[netty-3.2.5.Final.jar:na]
at com.alibaba.dubbo.remoting.transport.netty.NettyServer.doOpen(NettyServer.java:92) ~[dubbo-2.6.0.jar:2.6.0]
at com.alibaba.dubbo.remoting.transport.AbstractServer.(AbstractServer.java:63) ~[dubbo-2.6.0.jar:2.6.0]
... 38 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_201]
at sun.nio.ch.Net.bind(Net.java:433) ~[na:1.8.0_201]
at sun.nio.ch.Net.bind(Net.java:425) ~[na:1.8.0_201]
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[na:1.8.0_201]
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) ~[na:1.8.0_201]
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.bind(NioServerSocketPipelineSink.java:148) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleServerSocket(NioServerSocketPipelineSink.java:100) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:74) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.channel.Channels.bind(Channels.java:468) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.channel.AbstractChannel.bind(AbstractChannel.java:192) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.bootstrap.ServerBootstrap$Binder.channelOpen(ServerBootstrap.java:348) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.channel.Channels.fireChannelOpen(Channels.java:176) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketChannel.(NioServerSocketChannel.java:85) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.newChannel(NioServerSocketChannelFactory.java:142) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.newChannel(NioServerSocketChannelFactory.java:90) ~[netty-3.2.5.Final.jar:na]
at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:282) ~[netty-3.2.5.Final.jar:na]
... 40 common frames omitted
解决:将端口配置放到前面,如下: