I am having difficulty figuring out why my spring bean is not getting injected into my CXF web service that is being deployed into jboss. Here is the scenario:
I have multiple Service classes which implement an Interface
Here is Implementation # 1
@Service("retrieveService")
@Scope("prototype")
@Transactional(propagation=Propagation.REQUIRED)
public class RetrieveService extends BaseService implements IEuclidService
{
@Resource
private EntrLoanRepository entrLoanRepository;
@Override
public RetrieveResponse serve(RequestMessage request)
{
entrLoanRepository.findByEntrLoanId();
}
}
Here is Implementation # 2
@Service("disableService")
@Scope("prototype")
@Transactional(propagation=Propagation.REQUIRED)
public class DisableService extends BaseService implements IEuclidService
{
@Resource
private EntrLoanRepository entrLoanRepository;
@Override
public RetrieveResponse serve(RequestMessage request)
{
EntrLoan entrLoan = new EntrLoan();
entrLoan.setEndDate( new Date());
entrLoanRepository.save(entrLoan);
}
}
I have my cxf web service, into which I am expecting a spring (service) bean to be injected.
@javax.jws.WebService
public class Euclid implements IEuclid {
private IEuclidService euclidService
public MyResponse myMethod(MyRequest req)
{
<!-- How do I inject an instance of RetrieveService here ???-->
euclidService.serve();
}
}
I tried doing this:
euclidService = ctx.getBean("retrieveService", RetrieveService.class);
but I am getting the error message:
com.sgb.euclid.contracts.RetrieveEnterpriseLnIdRequest@31d908
***1 EuclidService is NULL
*****Instantiating Spring Bean
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'retrieveService' must be of type [com.sgb.euclid.ws.service.RetrieveService], but was actually of type [$Proxy98]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:360)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1102)
at com.sgb.euclid.ws.web.Euclid.retrieve(Euclid.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.webservices.deployers.WSComponentInstanceAssociationInterceptor.processInvocation(WSComponentInstanceAssociationInterceptor.java:49)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)
at org.jboss.as.webservices.invocation.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:111)
at org.jboss.wsf.stack.cxf.JBossWSInvoker.performInvocation(JBossWSInvoker.java:149)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.invoke(AbstractJAXWSMethodInvoker.java:178)
at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:64)
at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:129)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:236)
at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:88)
at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:156)
at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:221)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:141)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135)
at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:652)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:919)
at java.lang.Thread.run(Thread.java:662)
I do not quite understand what "type [$Proxy98]" is. I searched in the logs, but cannot see where it is coming from. I assume this is related to spring?? Eitherway, what am I doing wrong that I am unable to instantiate a spring bean keeping in mind that the beans are not defined in beans.xml, but rather annotated.
I feel I am missing something, but cannot quite put my finger on it.
As I am deploying on jboss, the configuration xmls are a bit different that the examples I am seeing online. Here is my jboss-cxf.xml:
<jaxws:endpoint id="POJOEndpoint"
implementor="com.sgb.euclid.ws.web.Euclid"
wsdlLocation="WEB-INF/wsdl/EnterpriseLoanIdentifier.wsdl"
address="http://localhost:8080/euclid-ws">
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
<jaxws:invoker>
<bean class="org.jboss.wsf.stack.cxf.InvokerJSE" />
</jaxws:invoker>
</jaxws:endpoint>
And here is the applicationContext-ws.xml:
<import resource="applicationContext-core.xml" />
<import resource="applicationContext-jpa.xml" />
<!-- setting up packages to scan for components -->
<context:component-scan base-package="com.sgb.euclid.ws.service" />
<tx:annotation-driven
transaction-manager="transactionManager" />
Here is the corresponding web.xml
<!-- setting up spring configuration to instantiate the spring container -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext-ws.xml</param-value>
</context-param>
<servlet>
<servlet-name>euclid</servlet-name>
<servlet-class>com.sgb.euclid.ws.web.Euclid</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>euclid</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I cannot figure out what my mistake is. Any help is appreciated....