Protocol handler start failedCaused by: java.net.SocketException: Permission denied

最近在使用mac启动项目的时候,发现原本在Windows下正常跑的项目报错如下:

Protocol handler start failedCaused by: java.net.SocketException: Permission denied

一模一样的代码,Windows下正常运行,但在mac上面却报错了,实在让人不解,所以这篇文章记录下解决的方案。


查找原因

经过Google发现,stackflow上面已经有大牛回答了这个问题,直接贴过来看看

Linux doesn't allow a normal user to bind to a TCP port that's <= 1024. There's a discussion of the reasons for that here. You're attempting to bind to 86 and, therefore, it's failing with "Permission denied". The quickest and safest solution is to configure the port with a value that's > 1024.
As you're using Boot's embedded Tomcat instance, the port's configured in application.propertiesusing the server.port property.

翻译过来就是说:

Linux不允许普通用户绑定到<= 1024 的TCP端口。 有一个讨论原因[这里](https://unix.stackexchange.com/questions/16564/why-are-the-first-1024-ports-restricted-to-the-root-user-only)。 你试图绑定到80,因此它失败了“权限被拒绝”。 最快和最安全的解决方案是使用大于1024的值配置端口。当您使用Boot的嵌入式Tomcat实例时,使用server.port属性在application.properties中配置端口。

总结

好了,原因找到了,原来在linux下,为了系统安全,使用小于1024端口时,需要被授权,最快的解决方案就是更换一个大于1024的端口。ok,直接把端口号更改为8080,重启,问题解决。

原文地址:https://www.cnblogs.com/yunjiandubu/p/10964753.html