Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:20880

问题描述: 在使用dubbo框架后,启动服务总是报错说端口占用

org.springframework.web.context.ContextLoader-331|Context initialization failed
Caused by: com.alibaba.dubbo.remoting.RemotingException: Failed to bind NettyServer on /192.x.0.x:20880, cause: Failed to bind to: /0.0.0.0:20880
Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:20880
Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:20880
Caused by: java.net.BindException: Address already in use

在这里插入图片描述
运行环境: linux + tomcat

解决过程: 经过网上各方面查找这个问题,得到思路如下:
1.dubbo提供者端口号占用,换一个端口试一下,例如:之前用的20880,现在可以换成20881,或者其他,此方式试了一下,我的问题并不属于这种情况的
2.用命令查看下是什么占用了端口,杀进程,重启.例如:
netstat -tunlp|grep 20880
ps -ef|grep 12345
kill -9 12345
./startup.sh
经过尝试还是占用
3.spring项目中的配置文件加载了两次,启动后端口占用的情况,是复核我的问题的,
启动后的项目日志看了一下,还真是配置文件加载了两次,如下:

2020-03-16 13:10:18.666|data.command.spring.global.code.GlobalCodePropertyConfigurer-25|begin Read globalCode.properties|
2020-03-16 13:10:18.671|data.command.spring.global.code.GlobalCodePropertyConfigurer-38|end Read globalCode.properties|
2020-03-16 13:10:23.480|data.command.spring.global.code.GlobalCodePropertyConfigurer-25|begin Read globalCode.properties|
2020-03-16 13:10:23.482|data.command.spring.global.code.GlobalCodePropertyConfigurer-38|end Read globalCode.properties|

这样问题就明确了,配置文件中dubbo提供者的端口加载一次,启动一次就可以了,现在启了两次,端口必须占用呀,然后修改tomcat配置文件,使其加载一次
修改tomcat/conf/server.xml

未修改之前的(Context标签内,docBase=“项目名称”)

 <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
       <Context path="" docBase="项目名称"  debug="0" reloadable="true"></Context>
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
      </Host>

修改之后的(Context标签内,docBase="")

 <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
            <Context path="" docBase=""  debug="0" reloadable="true"></Context>
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>

再来看下启动后的项目日志文件,配置文件加载了一次,端口占用的错误已经没有了


2020-03-16 13:26:54.393|data.command.spring.global.code.GlobalCodePropertyConfigurer-25|begin Read globalCode.properties|
2020-03-16 13:26:54.398|data.command.spring.global.code.GlobalCodePropertyConfigurer-38|end Read globalCode.properties|
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值