2

After the update from spring boot 2.7. to version 3 the strange error occurred, that no qualifying bean of type 'jakarta.xml.ws.WebServiceContext' is available. I followed the migration steps (javax to jakarta) and compiling the project works fine, but it cannot be started. The SOAP request needs the WebServiceContext because I need to extract some information from the header/body. Is there any way to inject the WebServiceContext? It was working fine in Spring Version 2.7

I already eliminated third-party libs that included older Spring versions so that an older version does not interfere with the functionality of Spring. I also looked at several discussions like this but none of them was helpful. As recommended, I tried to inject the WebServiceContext with a setter with the same result.

@jakarta.jws.WebService
public class MyEndpoint {
...

    private WebServiceContext context;

    @Resource
    public void setContext(WebServiceContext context) {
        this.context = context;
    }
...

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176

2 Answers2

0

if your are using maven try adding these dependency in pom.xml file

<dependency>
    <groupId>jakarta.xml.ws</groupId>
    <artifactId>jakarta.xml.ws-api</artifactId>
    <version>3.0.0</version>
</dependency>

if it doesn't work you can also try changing @Resource to @Autowired This may help Spring recognize the WebServiceContext as a bean that needs to be injected.

@jakarta.jws.WebService
public class MyEndpoint {
...
    @Autowired
    private WebServiceContext context;

    
    public void setContext(WebServiceContext context) {
        this.context = context;
    }
...

@Configuration
public class WebServiceConfig {
    
    @Bean
    public WebServiceContext webServiceContext() {
        return new WebServiceContext() {
            // implementation of WebServiceContext methods
        };
    }
}
  • Thanks for your response. The dependency is already in the pom. Also the approach with Autowired I have tried without success. With `@Autowired(required = false)` the application is able to start but the variable context is null. SpringBoot 3 must have some strange effects of the injections of the bean – rivendell10 Apr 04 '23 at 11:54
  • after adding dependency, try rebuilding and running your application again – Kamarthi Om prakash Apr 04 '23 at 11:56
0

I have faced this issue for a couple other beans in Spring Boot 3. Each time the issue has been related to trying to autowire a Bean that is an interface, not a class. One solution is to register a bean that returns an instance of a class that implements the interface in question.

In this case, the WebServiceContext from Jakarta is the interface, and the implementation class I chose is from org.apache.cxf.jaxws.context. I registered the following bean in an @Configuration class, and it fixed the issue:

import org.apache.cxf.jaxws.context.WebServiceContextImpl;
import jakarta.xml.ws.WebServiceContext;
import org.springframework.context.annotation.Configuration;

  @Bean
  public WebServiceContext webServiceContext() {
    return new WebServiceContextImpl();
  }

This approach makes configurations explicit, which may be nice. As a side note, there may also be a spring-boot-starter dependency you can include, which provides basic implementations for interfaces based on application.properties values, so that you don't have to configure them. I was not able to find one for this case, but I didn't look for very long