I am trying to learn spring 3 and working on an application which uses annotation based configuration instead of defining beans in *.xml. I keep getting this error whicxh i am not able to resolve. When used just with 2.5 version by defining beans in applicationContext*.xml works fine but when using annotation it does not work
org.hibernate.SessionException: Session is closed
my *-servlet.xml
My Dao Class :-Code:<?xml version="1.0" encoding="UTF-8"?> <beans default-lazy-init="false" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config /> <context:component-scan base-package="com.foo.web.mvc"> <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation" /> </context:component-scan> <context:component-scan base-package="com.foo.dao"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/> </context:component-scan> <context:component-scan base-package="com.foo.service"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/> </context:component-scan> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="alwaysUseFullPath" value="false" /> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" /> <bean id="contentNegotiatingViewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="mediaTypes"> <map> <entry key="html" value="text/html" /> </map> </property> <property name="viewResolvers"> <list> <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" /> <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </list> </property> </bean> </beans>
my applicationContext.xmlCode:@Repository public class UserDao { @Autowired private SessionFactory sessionFactory; @Transactional(readOnly=true) public List<User> findUsers(String id) { Session session = sessionFactory.getCurrentSession(); .... } }
Code:<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> . . . </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> . . </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <aop:config> <aop:pointcut id="daoOperation" expression="execution(* *..dao.*(..))"/> <aop:advisor id="managerTx" advice-ref="txAdvice" pointcut-ref="daoOperation" order="1"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="find*" read-only="true"/> <tx:method name="*"/> </tx:attributes> </tx:advice>


Reply With Quote