You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在无默认JAX-WS栈的Payara Micro中提供SOAP接口?

How to Implement SOAP Endpoints with Payara Micro (No Default JAX-WS Stack)

Great question! Since Payara Micro is built to stay lightweight, it doesn’t include the JAX-WS stack out of the box. But there are several reliable ways to add SOAP support to your application—here are the most practical approaches:

1. Use Metro (GlassFish’s Native JAX-WS Implementation)

Metro is the same JAX-WS stack used in Payara Server Full, so it’s fully compatible with Payara Micro. Here’s how to set it up:

  • Add Metro dependencies to your project:
    If you’re using Maven, include these in your pom.xml:

    <dependencies>
        <!-- JAX-WS API -->
        <dependency>
            <groupId>javax.xml.ws</groupId>
            <artifactId>jaxws-api</artifactId>
            <version>2.3.1</version>
            <scope>provided</scope>
        </dependency>
        <!-- Metro runtime -->
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.3.5</version>
            <scope>runtime</scope>
        </dependency>
        <!-- Metro Servlet integration -->
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-servlet</artifactId>
            <version>2.3.5</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    
  • Annotate your SOAP service:
    Create your service class with the standard @WebService annotation:

    @WebService
    public class HelloSoapService {
        @WebMethod
        public String sayHello(String name) {
            return "Hello, " + name + "!";
        }
    }
    
  • Register the service:
    Let Metro auto-scan for services by adding a sun-jaxws.xml file in WEB-INF:

    <?xml version="1.0" encoding="UTF-8"?>
    <endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
        <endpoint
            name="HelloSoapService"
            implementation="com.yourpackage.HelloSoapService"
            url-pattern="/hello-soap"/>
    </endpoints>
    
  • Package and run:
    Bundle your app as a WAR or executable JAR with Payara Micro embedded. When you start Payara Micro, it will pick up the Metro runtime and deploy your SOAP endpoint.

2. Use Apache CXF

Apache CXF is another popular JAX-WS implementation that works seamlessly with Payara Micro. Here’s the setup:

  • Add CXF dependencies:
    In your pom.xml:

    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.6.2</version>
        </dependency>
    </dependencies>
    
  • Configure CXF Servlet:
    Register the CXF servlet using Java-based configuration:

    @Configuration
    public class CxfConfig {
        @Bean
        public ServletRegistrationBean<CXFServlet> cxfServlet() {
            ServletRegistrationBean<CXFServlet> servlet = new ServletRegistrationBean<>(new CXFServlet(), "/soap/*");
            servlet.setLoadOnStartup(1);
            return servlet;
        }
    
        @Bean
        public Endpoint helloEndpoint() {
            EndpointImpl endpoint = new EndpointImpl(new HelloSoapService());
            endpoint.publish("/hello");
            return endpoint;
        }
    }
    
  • Run your app:
    Package and deploy to Payara Micro as usual. Your SOAP endpoint will be available at http://localhost:8080/soap/hello.

3. Bundle Payara Full’s JAX-WS Modules (Advanced)

If you want to use the exact same JAX-WS stack as Payara Server Full, you can bundle the required modules with Payara Micro:

  • Identify required modules:
    Key modules include javax.ws.rs.api, com.sun.xml.ws.jaxws-rt, and com.sun.xml.ws.jaxws-api.

  • Start Payara Micro with modules added:
    Use the --addModule parameter when launching:

    java -jar payara-micro.jar --addModule javax.ws.rs.api --addModule com.sun.xml.ws.jaxws-rt --addModule com.sun.xml.ws.jaxws-api deploy your-app.war
    

    Note: This requires access to Payara Server Full’s module JARs and version compatibility with your Payara Micro build.

Key Tips

  • Avoid Dependency Conflicts: Don’t include both Metro and CXF in the same project—stick to one implementation.
  • Uber-Jar Packaging: If building an executable JAR, ensure all JAX-WS runtime dependencies are included in the final bundle.
  • Test Thoroughly: Use tools like SoapUI or curl to validate your SOAP endpoint works as expected.

内容的提问来源于stack exchange,提问作者peez80

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:16:01