I have a webservice where I require to create a new bean for every request. 
When I use cxf-servlet.xml it works fine but however when I use a
ContextLoaderListener, it fails.
I have also added a
org.springframework.web.context.request.RequestContextListener.
My web.xml is as follows :
<?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="WebApp_ID"
version="2.5">
  <display-name>CustomerProj</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description>Apache CXF Endpoint</description>
    <display-name>cxf</display-name>
    <servlet-name>cxf</servlet-name>
   
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>cxf</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>60</session-timeout>
  </session-config>
  
   <context-param>
    <param-name>contextConfigLocation</param-name>    
    <param-value>/WEB-INF/cust-beans.xml</param-value>
  </context-param> 
  <listener>
   
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>
   <listener>
   
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  
</web-app>

If I use cxf-servlet.xml as teh default bean creation file, it works fine.
What am I doing wrong.

I get teh following error
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'serviceimpl' defined in ServletContext resource
[/WEB-INF/cust-beans.xml]: Error setting property values; nested exception
is org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1:
org.springframework.beans.MethodInvocationException: Property 'ops' threw
exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'scopedTarget.operation': 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.
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1363)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1085)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
        at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
        at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
        at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
        at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
        at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
        at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
        at 
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
        at 
org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
        at 
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
        at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
        at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
        at 
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
        at 
org.apache.catalina.core.StandardService.start(StandardService.java:525)
        at 
org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1:
org.springframework.beans.MethodInvocationException: Property 'ops' threw
exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'scopedTarget.operation': 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.
        at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
        at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
        ... 37 more

My bean file is :
eans xmlns="http://www.springframework.org/schema/beans";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:jaxws="http://cxf.apache.org/jaxws";  
        xmlns:soap="http://cxf.apache.org/bindings/soap";
xmlns:aop="http://www.springframework.org/schema/aop"; 
        xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd";>
        

        <bean id="custapi" class="com.example.cust.CustomerAPI" scope="request">
        
    </bean>
    

        <bean id="operation" class="com.example.cust.CustomerOperationImpl"
scope="request">
          
          
          <aop:scoped-proxy proxy-target-class="false"/>
          <property name="custApi" ref="custapi"/>
     </bean>
    
    <bean id="serviceimpl" class="com.example.cust.CustomerServiceBridge">
         <property name="ops" ref="operation"/>
    </bean>
    
    <jaxws:endpoint xmlns:tns="http://customerservice.example.com/";
                id="customerservice" implementor="#serviceimpl"
                wsdlLocation="WEB-INF/CustomerService.wsdl"
endpointName="tns:CustomerServicePort"
                serviceName="tns:CustomerServiceService" 
address="/CustomerServicePort">
                <jaxws:features>
                        <bean class="org.apache.cxf.feature.LoggingFeature" />
                </jaxws:features>
        </jaxws:endpoint>

        


</beans>




--
View this message in context: 
http://cxf.547215.n5.nabble.com/Creating-request-prototype-scoped-beans-fails-in-CXF-sevlet-tp5735095.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to