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

爱被打了一巴掌 2023-07-15 09:19 62阅读 0赞

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

  1. org.springframework.web.context.ContextLoader-331|Context initialization failed
  2. 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
  3. Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:20880
  4. Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:20880
  5. 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项目中的配置文件加载了两次,启动后端口占用的情况,是复核我的问题的,
启动后的项目日志看了一下,还真是配置文件加载了两次,如下:

  1. 2020-03-16 13:10:18.666|data.command.spring.global.code.GlobalCodePropertyConfigurer-25|begin Read globalCode.properties|
  2. 2020-03-16 13:10:18.671|data.command.spring.global.code.GlobalCodePropertyConfigurer-38|end Read globalCode.properties|
  3. 2020-03-16 13:10:23.480|data.command.spring.global.code.GlobalCodePropertyConfigurer-25|begin Read globalCode.properties|
  4. 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=“项目名称”)

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

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

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

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

  1. 2020-03-16 13:26:54.393|data.command.spring.global.code.GlobalCodePropertyConfigurer-25|begin Read globalCode.properties|
  2. 2020-03-16 13:26:54.398|data.command.spring.global.code.GlobalCodePropertyConfigurer-38|end Read globalCode.properties|

发表评论

表情:
评论列表 (有 0 条评论,62人围观)

还没有评论,来说两句吧...

相关阅读