Java Spring Boot发布REST&;SOAP并行

Java Spring Boot发布REST&;SOAP并行,java,web-services,spring-boot,binding,Java,Web Services,Spring Boot,Binding,我无法连接到在运行Spring引导应用程序的端口9000上侦听的SOAP服务。应用程序在docker容器中运行。问题是soap端点正在本地主机而不是0.0.0.0上侦听 我想在0.0.0.0:9000而不是127.0.0.1:9000上绑定soap服务。我如何才能做到这一点? 这里是我的设置: Application.properties soap.url = http://localhost:9000/ rest.url = http://localhost:9090/ server.port

我无法连接到在运行Spring引导应用程序的端口9000上侦听的SOAP服务。应用程序在docker容器中运行。问题是soap端点正在本地主机而不是0.0.0.0上侦听

我想在0.0.0.0:9000而不是127.0.0.1:9000上绑定soap服务。我如何才能做到这一点?

这里是我的设置:

Application.properties
soap.url = http://localhost:9000/
rest.url = http://localhost:9090/
server.port = 9090
弹簧启动正确

Springboot-Startup-log
2017-05-04 06:36:53.095  INFO 1 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9090 (http)
2017-05-04 06:36:53.110  INFO 1 --- [           main] ch.gemdat.Application                    : Started Application in 28.285 seconds (JVM running for 29.465)
2017-05-04 06:36:55.387  INFO 1 --- [           main] myapp                                    : - services/soap/form/call/v1
2017-05-04 06:36:55.388  INFO 1 --- [           main] myapp                                    : >> myapp successfully started in 0:31 <<
我完全可以连接到端口9090上运行的所有服务。因为他们在0.0.0.0上正确收听

以下是我发布soap服务的方式:

private static void publishSoapServices() {
    MyAppLogger.info("Register soap endpoints...");
    BeanDefinitionRegistry beanDefRegistry = new SimpleBeanDefinitionRegistry();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanDefRegistry);
    scanner.addIncludeFilter(new AssignableTypeFilter(MyAppService.class));
    scanner.scan(Constants.SOAP_PACKAGE);

    for (String bean : beanDefRegistry.getBeanDefinitionNames()) {
        if (!bean.contains("springframework")) {
            try {
                Class<?> soapClass = Class.forName(beanDefRegistry.getBeanDefinition(bean).getBeanClassName());
                if (MyAppSoapService.class.isAssignableFrom(soapClass)) {
                    MyAppService soapService = (MyAppService) soapClass.newInstance();
                    Endpoint.publish(PropertyReader.getValue("soap.url") + soapService.getEndpoint(), soapService);
                    ctx.getAutowireCapableBeanFactory().autowireBean(soapService);
                    MyAppLogger.info("- " + soapService.getEndpoint());
                }
            } catch (Exception e) {
                MyAppLogger.error("Soap service ''{0}'' could not be published.", e, bean);
            }
        }
    }
}

经过反复试验,我找到了解决办法

Application.properties
soap.url = http://0.0.0.0:9000/
rest.url = http://localhost:9090/
server.port = 9090
解决方案是将
application.properties
方法中使用的
soap.url
设置为
http://0.0.0.0:9000/
。它不适用于我最初尝试的
0.0.0.0:9000/

为什么它适用于rest端口? 但事实并非如此。rest服务之所以能够工作,是因为端口未在
应用程序.properties
rest.url
下发布。通过从application.properties读取
server.port
,它们被绑定到初始的spring boot应用程序端口集。端口被tomcats在接口上侦听
0.0.0.0


正如p.J.Meisch所说的,问题在于绑定到
localhost
soap.url

Endpoint.publish(PropertyReader.getValue(http://localhost:9000/)+soapService.getEndpoint(),soapService)这不是有效的Java代码,如果您使用localhost:9000调用它,那么您将绑定到localhostonly@P.J.Meisch谢谢你的评论。你说得对。我想让代码更容易理解,并用值替换application.properties中的
键。但这是错的。我更正了它以显示实际的代码。我只是想回答这个问题,您需要将端点绑定到
http://0.0.0.0:9000/
而不是本地主机。很高兴你自己找到了;-)谢谢你的帮助。我花了两天时间试图解决这个问题。你会因此获得额外的投票权。
"Ports": {
            "9000/tcp": [
                {
                    "HostIp": "0.0.0.0",
                    "HostPort": "9000"
                }
            ]
Application.properties
soap.url = http://0.0.0.0:9000/
rest.url = http://localhost:9090/
server.port = 9090