I would like to inject ( @Autowired
or @Resource
) beans created by Spring ( 3.x
or 4.x
) into a class that implements a JAX-WS interface (reference implementation).
I tested it on Tomcat 6 and it works, but on Tomcat 7, it looks like the container specification has changed and the contexts are different.
I have already used the proposed integration (which even has bad documentation) as suggested in:
In this example, the sun-jaxws.xml
file is replaced by a Spring configuration file. However, in my example I'm doing everything with @Configuration
, since I was trying to avoid XMLs. I do not know how to make this change to the JAX-WS Endpoint to be able to use a spring-injected bean, without having to use applicationContext.getBean("meuBean")
.
Note: I read everything, believe me. Some suggest extending SpringBeanAutowiringSupport
, others putting @PostConstructor
, but nothing works on Tomcat 7.
Is it a container definition? Can not really do it? This is the main question, for me to give up once and for all. ;)
UPDATE
@utluiz, thanks for the reply. Basically I used the Mkyong example, however I want to do the injection without XML and the configuration through the @Configuration
java class I created. Meu web.xml
looks like this:
org.springframework.web.context.ContextLoaderListener
<!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContext
instead of the default XmlWebApplicationContext -->
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<!-- Configuration locations must consist of one or more comma- or space-delimited
fully-qualified @Configuration classes. Fully-qualified packages may also be
specified for component-scanning -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.mkyong.ContextConfiguration</param-value>
</context-param>
<servlet>
<servlet-name>jaxws-servlet</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSSpringServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
and my configuration class:
@Configuration
@ComponentScan(basePackages = "com.mkyong")
@ImportResource({"classpath*:/applicationContext.xml"})
public class ContextConfiguration {
}
However, the endpoint mapping gets in this xml (applicationContext.xml) as follows:
<wss:binding url="/hello">
<wss:service>
<ws:service bean="#helloWorldWS"/>
</wss:service>
</wss:binding>
<!-- Web service methods -->
<bean id="helloWs" class="com.mkyong.ws.HelloWorldWS">
<property name="helloWorldBo" ref="HelloWorldBo" />
</bean>
<bean id="HelloWorldBo" class="com.mkyong.bo.impl.HelloWorldBoImpl" />
I would like to remove this XML, for this, I need to configure the wss:binding
stretch within my class @Configuration
in java. This I do not know how to do.
Note: It would be okay to use this XML as well, but I wanted to do the injections via java and not via XML. But it seems that spring ignores the applicationContext.xml when I use the context setting via java.
I do not know if it was clear, the case is that I have no problem with the following snippet being in the XML:
<wss:binding url="/hello">
<wss:service>
<ws:service bean="#helloWorldWS"/>
</wss:service>
</wss:binding>
I just want to remove the bean definitions, so I can use @Resource
/ @Autowired
and @Component
.