samedi 28 mars 2015

spring request scope in HttpRequestHandlerServlet does not work

I can't anderstand why it configuration does not work.


I make spring web applcation without mvc and use HttpRequestHandlerServlet class. I need that all beans use one Connection in one request. And I set request scope in Connection bean but when I run it:



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.


help me pls to resolve it


my web.app is:



<web-app version="3.1" xmlns="http://ift.tt/19L2NlC"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/19L2NlC
http://ift.tt/1drxgYl">

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/app-context.xml</param-value>
</context-param>

<servlet>
<servlet-name>monitoring</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>monitoring</servlet-name>
<url-pattern>/monitoring</url-pattern>
</servlet-mapping>


my app-context is:



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:context="http://ift.tt/GArMu7"
xmlns:aop="http://ift.tt/OpNdV1"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/1jdM0fG
http://ift.tt/GArMu7
http://ift.tt/1jdLYo7
http://ift.tt/OpNdV1
http://ift.tt/1feTlrW">

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost/nts" />
<property name="user" value="root" />
<property name="password" value="root" />

<property name="maxPoolSize" value="20" />
<property name="minPoolSize" value="5" />
<property name="maxStatements" value="100" />
<property name="testConnectionOnCheckout" value="true" />
</bean>

<bean id="conn" class="java.sql.Connection" factory-bean="dataSource" factory-method="getConnection" scope="request"/>

<bean id="monitoring" class="com.sotas.terminal.server.servlet.MonitoringServlet">
<property name="monitoringService">
<bean class="com.sotas.terminal.server.service.MonitoringService">
<property name="conn" ref="conn"/>
<property name="providerDAO">
<bean class="com.sotas.terminal.server.dao.ProviderDAOImpl">
<property name="conn" ref="conn"/>
</bean>
</property>
</bean>
</property>
</bean>

Aucun commentaire:

Enregistrer un commentaire