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...
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());
}
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.