Skip to content

Provide runtime hints for the reflection of Spring WS - #1946

Closed
sharanggupta wants to merge 2 commits into
spring-projects:mainfrom
sharanggupta:gh-1329-runtime-hints
Closed

sharanggupta wants to merge 2 commits into
spring-projects:mainfrom
sharanggupta:gh-1329-runtime-hints

Conversation

@sharanggupta

Copy link
Copy Markdown

This is a first step for #1329: it provides the runtime hints for the reflection that Spring WS performs itself, as suggested in #1329 (comment), so that an application does not have to collect them with the tracing agent.

What it registers

A WebServicesRuntimeHints registrar in META-INF/spring/aot.factories registers:

  • The properties files of the default strategies of the WebServiceTemplate, the MessageDispatcher, the SoapMessageDispatcher and the MessageDispatcherServlet, and the constructors of the strategies they list, which the DefaultStrategiesHelper instantiates. The registrar reads the same properties files, so the hints follow any change to the defaults.
  • The constructors of SoapMethodArgumentResolver and SoapHeaderElementMethodArgumentResolver, which the DefaultMethodEndpointAdapter instantiates by class name.
  • The types of the optional XML libraries (DOM4J, JAXB, JDOM, StAX, XOM) that the DefaultMethodEndpointAdapter detects by class name, so that the detection works in a native image when the library is present.
  • The constructor of the normalize-space XPath function of the JDK, which the JDK instantiates reflectively when the WS-Addressing support evaluates its expressions.

This covers what the configurations in the issue had to register by hand, except the internals of third-party libraries (the SAAJ resource bundle and the JAXB runtime classes), which belong to those libraries.

Endpoint methods

@PayloadRoot, @SoapAction and @Action are now meta-annotated with @Reflective, in the same way that @RequestMapping is for Spring MVC. During AOT processing, the methods of @Endpoint beans that they map are registered for invocation, so the endpoint mappings can find them and the MethodEndpoint can invoke them in a native image. The repeated forms work as well, as MergedAnnotations sees the annotations inside @PayloadRoots and @SoapActions.

The payload types of the endpoints, such as JAXB classes, still need their own hints, for instance with @RegisterReflectionForBinding. A ReflectiveProcessor that registers them from the @RequestPayload and @ResponsePayload signatures could follow, like ControllerMappingReflectiveProcessor does for @RequestBody, if you think that it belongs in Spring WS.

Testing

Developed test first: the tests failed against main (no hints are registered), and pass with the change.

  • WebServicesRuntimeHintsTests loads the registrars from aot.factories, like the AOT engine does, and checks the hints with RuntimeHintsPredicates. For each default strategies file, it checks the resource and every strategy that the file lists.
  • EndpointMappingAnnotationsRuntimeHintsTests runs the ReflectiveRuntimeHintsRegistrar on a sample endpoint, and checks that the mapped methods, including repeated annotations, are registered for invocation and that an unmapped method is not.
  • ./gradlew :spring-ws-core:check :spring-ws-core:javadoc passes locally on JDK 25 (1047 tests in spring-ws-core, none skipped).

I did not build a native image to verify this end to end: that needs more memory than my machine has to spare. The hints match the configurations reported in the issue, which were verified in native images.

Spring WS uses reflection in a few places that a GraalVM native image
cannot see, so users had to find and register hints themselves.

This commit registers, through META-INF/spring/aot.factories:

* the properties files of the default strategies of WebServiceTemplate,
  MessageDispatcher, SoapMessageDispatcher and MessageDispatcherServlet,
  and the constructors of the strategies they list, which
  DefaultStrategiesHelper instantiates
* the constructors of the SOAP method argument resolvers, and the types
  of the optional XML libraries, that DefaultMethodEndpointAdapter loads
  by class name
* the constructor of the normalize-space XPath function of the JDK, which
  the WS-Addressing support evaluates

It also meta-annotates @PayloadRoot, @SoapAction and @action with
@Reflective, so that the endpoint methods they map can be found and
invoked, like @RequestMapping does for Spring MVC handler methods.

See spring-projectsgh-1329

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 15, 2026
Loading MessageDispatcherServlet requires the Servlet API, which is an
optional dependency of spring-ws-core, so referencing it with a class
literal made the registrar fail during AOT processing for applications
without the Servlet API, such as client-only ones.

Reference all the hinted types by name, and register the types of the
optional XML libraries only when they are present.

See spring-projectsgh-1329

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
@sharanggupta

Copy link
Copy Markdown
Author

I pushed a follow-up commit: the registrar now references all the hinted types by name. With the MessageDispatcherServlet.class literal, loading the registrar required the Servlet API, which is optional for spring-ws-core, so AOT processing would have failed for applications without it (client-only ones, for instance). The types of the optional XML libraries are now registered only when they are present.

@snicoll

snicoll commented Oct 15, 2026

Copy link
Copy Markdown
Member

See #1329 (comment) - We don't have the bandwidth to review and support this going forward.

@snicoll snicoll closed this Oct 15, 2026
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants