2

So I already learnt that integration of spring and jax-ws is not an easy thing. I want to inject a spring bean into jax-ws service, but for some reason I get an exception during the deployment:

 Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.springframework.web.context.ContextLoaderListener|#]

this is my jax-ws configuration:

<wss:binding url="/ws/users">
    <wss:service>
        <ws:service bean="#usersWs"/>
    </wss:service>
</wss:binding>

<bean id="usersWs" class="love.service.endpoint.implementations.UserServiceImpl" />

And this is my service:

@WebService
public class UserServiceImpl implements UserService{

@EJB
private DBManager dbmanager;

@Override
@WebMethod
public boolean addUser(String name, String password, String email) {

    return false;
}

@Override
@WebMethod
public boolean isUsernameAvailable(String username) {
    return dbmanager.isLoginAvailable(username);
}

@Override
@WebMethod
public boolean isEmailAvailable(String email) {
    return dbmanager.isEmailAvailable(email);
}

}

and finally my bean configuration:

    <bean id="dbmanager" class="love.commons.database.DBManager" scope="request">
    <aop:scoped-proxy/>    
</bean>

I also tried injecting the bean into some controllers and then it works perfectly well. If I replace @EJB with @Autowired, the application starts, but the service still doesn't work. When I tried sending a message to it, my only response was the following:

    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
         <faultcode>S:Server</faultcode>
         <faultstring>Error creating bean with name 'scopedTarget.dbmanager': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.</faultstring>
      </S:Fault>
   </S:Body>
</S:Envelope>
Kamil Janowski
  • 1,872
  • 2
  • 21
  • 43

0 Answers0