• Mac下解决SpringBoot启动时端口被占用


    启动 SpringBoot 项目时候,出现了下面的错误。

    复制代码
    java.net.BindException: Address already in use
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:444)
        at sun.nio.ch.Net.bind(Net.java:436)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:473)
        at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:617)
        at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:444)
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1010)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:459)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:335)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:58)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:53)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:259)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:140)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:552)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:293)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:749)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:738)
        at hello.Application.main(Application.java:12)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
        at java.lang.Thread.run(Thread.java:744)
    复制代码

    尝试以下两条命令没有结果。。。(原因:项目启动在 Idea 中跑的,不是用 java -jar 命令去跑的)

    bogon:~ zacky$ ps aux | grep "0.0.1-SNAPSHOT.jar" | grep -v grep | awk '{print $2}' | xargs kill
    bogon:~ zacky$ ps aux | grep "0.0.1-SNAPSHOT.jar" | grep -v grep | awk '{print $2}' | xargs kill -9

    使用 lsof 命令查看端口。

    bogon:~ zacky$ lsof -i :8090 | grep LISTEN
    Shadowsoc  542 zacky    6u  IPv4 0xf627dab35600d4b      0t0  TCP *:8090 (LISTEN)
    java      1740 zacky  125u  IPv6 0xf627dab2d25b323      0t0  TCP bogon:8090 (LISTEN)
    bogon:~ zacky$ kill -9 1740

    问题解决。

    转自:https://www.cnblogs.com/zacky31/p/9258268.html

  • 相关阅读:
    查看tomcat启动文件都干点啥---server对象
    Spring的AOP浅尝
    Spark1.3.0安装
    HMM的概率计算问题和预测问题的java实现
    C语言实现求字符串子集问题
    AdaBoost的java实现
    ID3决策树预测的java实现
    决策树ID3算法的java实现
    Naive Bayes在mapreduce上的实现
    Kmeans在MapReduce中的实现
  • 原文地址:https://www.cnblogs.com/sunshinekevin/p/12653722.html
Copyright © 2020-2023  润新知