@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 ! ");
        }
    }
@Test
    public void testFindPort() {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(TomcatServletWebServerFactory.class);
        beanFactory.registerBeanDefinition("webServerFactory", beanDefinition);

        int port = PortUtils.findPort(beanFactory);
        Assertions.assertEquals(8080, port);
    }