简体   繁体   中英

How can I configure the target namespace globally in JAX-WS web services?

I have a lot of endpoints annotated with @WebService(targetNamespace = "mynamespace") . Every @WebResult and @WebParam has the same definition of targetNamespace = "mynamespace" .

Is there a way to configure JAX-WS (Metro implementation) to use "mynamespace" as targetNamespace by default?

I would like to use the annotations without any attributes and get rid of the duplicate declarations, just like convention over configuration.

Only put the targetNamespace in the service endpoint interface or service implementation bean .

/**
* Annotated Implementation Object
*/
@WebService(
    name = "CustomerService",
    targetNamespace = "http://org.company.services"
)
public class CustomerService {
    @WebMethod
    @WebResult(name="CustomerRecord")
    public CustomerRecord locateCustomer(
        @WebParam(name="FirstName") String firstName,
        @WebParam(name="LastName") String lastName,
        @WebParam(name="Address") USAddress addr) {
        ...
    }
};

If @WebResult or @WebParam have no targetNamespace , the default is the targetNamespace for the Web Service.

In another hand, you can avoid the all annotations and only use the @WebService if you don't need something custom with JAX-B.

See more in JSR-181 Web Services Metadata for the JavaTM Platform

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM