@SuppressWarnings("all")
    public static int findPort(final BeanFactory beanFactory) {
        try {
            //works fine for springboot 2.x
            return getPort(beanFactory, "org.springframework.boot.web.server.AbstractConfigurableWebServerFactory");
        } catch (Exception ignored) {
        }
        try {
            //works fine for springboot 1.x
            return getPort(beanFactory, "org.springframework.boot.context.embedded.AbstractConfigurableEmbeddedServletContainer");
        } catch (Exception ignored) {
        }
        try {
            //works for springmvc with external tomcat
            return PortUtils.getPort();
        } catch (Exception e) {
            throw new ShenyuException("can not find port automatically ! ");
        }
    }
Note: springboot 1.x version has been made compatible.
Note: springmvc with external tomcat had been made compatible.
Note: In this way, no matter what container is actually used, you can get the port that is actually started in the end.
Note: see {@code org.springframework.boot.context.embedded.AbstractConfigurableEmbeddedServletContainer#getPort()}
for springboot 1.x;
Note: see {@code org.springframework.boot.web.server.AbstractConfigurableWebServerFactory#getPort()}
for springboot 2.x

@param beanFactory beanFactory
@return port number
@throws ShenyuException when can not find port
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/utils/PortUtils.java