WSServletContainerInitializer and SpringBeanAutowiringSupport

I have some integration issues regarding the mentioned classes, but only with "too new" versions of tomcat.

Base installation: web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="FooService" version="2.5" metadata-complete="true"> <display-name>FooService</display-name> <servlet> <servlet-name>jax-ws</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:/applicationContext.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class> </listener> </web-app> 

FooServiceImpl:

 @WebService(serviceName = ServiceInfo.SERVICENAME, targetNamespace = ServiceInfo.TARGETNAMESPACE, endpointInterface = "bar.FooService") @HandlerChain(file = "/handler-chain.xml") public class FooServiceImpl extends SpringBeanAutowiringSupport implements FooService { @Autowired private Bar bar; << some methods using the injected bar singleton >> 

JAX-WS dependency: compile 'com.sun.xml.ws:jaxws-rt:2.2.7' Spring version: 3.1.2.RELEASE

With Tomcat 7.0.22 I have no problem. The declared version of webapp in web.xml is 2.5. Tomcat 7.0.22 does not handle WSServletContainerInitializer. So, as indicated in web.xml, the ContextLoaderListener is initialized first, so the Bar instance will be available in the WebApplicationContext. Then WSServletContextListener creates an instance of FooServiceImpl, and the work works, and everyone is happy.

But ... My colleague tried this with Tomcat 7.0.30, and the auto installation did not work (7.0.32 gives the same problem, now it is the newest). This really did not work, because the new version of Tomcat processed the WSServletContainerInitializer, not taking into account version 2.5 of the webapp (and metadata-complete = "true").

I found a possible solution. I commented on the body of web.xml, changed the version of webapp 3.0 and created WebapplicationInitializer:

 public class MyInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { ContextLoader loader = new ContextLoader(); loader.initWebApplicationContext(servletContext); } } 

This worked great for me. But not for my colleague ... If he tried to start the application, the WSServletContainerInitializer was launched first, which created exactly the same wiring problem as above.

Obviously, we can β€œcrack” the problem by getting rid of SpringBeanAutowiringSupport and enter Bar manually from a getter or web method or in any other way. But SpringBeanAutowiringSupport will be much clearer, so we would like to use it if there is a good solution to the above problems.

UPDATE: this causes problems: https://issues.apache.org/bugzilla/show_bug.cgi?id=53619

+4
source share
1 answer

for me, the solution was to call the following when the link to the auto host is null

 processInjectionBasedOnCurrentContext(this); 

I hope this helps everyone.

+4
source

Source: https://habr.com/ru/post/1438722/


All Articles