java - Spring request scope in HttpRequestHandlerServlet does not work -


i can't understand why configuration not work.

i make spring web applcation without mvc , use httprequesthandlerservlet class. need beans use 1 connection in 1 request. , set request scope in connection bean when run it:

illegalstateexception: no thread-bound request found: referring request attributes outside of actual web request, or processing request outside of receiving thread? if operating within web request , still receive message, code running outside of dispatcherservlet/dispatcherportlet: in case, use requestcontextlistener or requestcontextfilter expose current request. 

my web.app is:

<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"      xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"      xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">  <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://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:aop="http://www.springframework.org/schema/aop"    xsi:schemalocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context.xsd     http://www.springframework.org/schema/aop      http://www.springframework.org/schema/aop/spring-aop.xsd">  <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> 

the error message pretty helpful. since aren't using dispatcher servlet in web.xml (as standard spring mvc app):

<servlet> <servlet-name>springapp</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> 

you need find way give spring access request. adding requestcontextlistener web.xml should trick:

<listener>     <listener-class>      org.springframework.web.context.request.requestcontextlistener     </listener-class>   </listener> 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -