0

in my project it's necessary to inject a value from the application.properties file, profile-dependent, into the endpoint-class to the namespace-variable of the @PayloadRoot annotation.

The problem: the namespace-value must be a constant and in spring I can't inject a value into a final variable. I find an advice to inject in this way:

@PayloadRoot(namespace = "${my.namespace}", localPart = "getMyRequest")
@ResponsePayload
public JAXBElement<MyResult> myMethod(@RequestPayload JAXBElement<MyInput> request) {

but ... it doesn't work. Has anyone a working solution?

Thanks...

JMarky
  • 289
  • 2
  • 3
  • 8

1 Answers1

0

You could do one of the following:

1) Use reflection once you have the appropriate value (but you need to make sure that you set the value before the endpoint mapping occurs): example here

2) Extends the class PayloadRootAnnotationMethodEndpointMapping and in the method getLookupKeysForMethod, use a custom a method getQNameFromAnnotation where you will inject the correct value of the namespace.

private QName getQNameFromAnnotation(PayloadRoot payloadRoot) {
    return new QName(/*INJECT YOURNAMESPACE HERE*/, payloadRoot.localPart());
}
Community
  • 1
  • 1
VirtualTroll
  • 3,077
  • 1
  • 30
  • 47
  • Hi VirtualTroll, thanks for your qualified answer. My problem was, that I had three server (devel, test, prod) running with my webservice. each different webservice needs a own wsdl with an individual address-location (that points to the right server). thats the essential fact. the namespace in the wsdl-file can be the same in the three wsdl-files. and so there's no need for a profile-related namespace value in the PayloadRoot-annotation. That solved my problem. but good to know, there's a another solution if it must be profile-dependent. – JMarky May 17 '17 at 14:33