java - Open hibernate session OpenSessionInViewFilter doens't work -
i'm using hibernate + spring4 create web site,
here web.xml
<!-- spring mvc --> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.contextloaderlistener </listener-class> </listener> <!-- loads spring security config file --> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/spring-security.xml</param-value> </context-param> <!-- spring security --> <filter> <filter-name>springsecurityfilterchain</filter-name> <filter-class>org.springframework.web.filter.delegatingfilterproxy </filter-class> </filter> <filter-mapping> <filter-name>springsecurityfilterchain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>hibernatefilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.opensessioninviewfilter</filter-class> <init-param> <param-name>sessionfactorybeanname</param-name> <param-value>sessionfactoryhhd</param-value> </init-param> </filter> <filter-mapping> <filter-name>hibernatefilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <error-page> <error-code>404</error-code> <location>/web-inf/views/404.jsp</location> </error-page>
spring-security.xml
<http auto-config="true"> <intercept-url pattern="/developper/**" access="hasrole('role_admin')" /> <intercept-url pattern="/dashboard/**" access="hasrole('role_consult')" /> <intercept-url pattern="/index/**" access="hasrole('role_operateur')" /> <form-login login-page="/login" default-target-url="/dashboard" authentication-failure-url="/login?error" username-parameter="username" password-parameter="password" /> <logout logout-success-url="/login?logout" /> <access-denied-handler error-page="/403" /> <!-- enable csrf protection --> <csrf disabled="false"/> </http> <beans:bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <beans:property name="driverclassname" value="${jdbc.postgresql.hhd.driverclassname}" /> <beans:property name="url" value="${jdbc.postgresql.hhd.url}" /> <beans:property name="username" value="${jdbc.postgresql.hhd.username}" /> <beans:property name="password" value="${jdbc.postgresql.hhd.password}" /> </beans:bean> <beans:bean id="bcrypt" class="org.springframework.security.crypto.bcrypt.bcryptpasswordencoder"/> <authentication-manager alias="authenticationmanager"> <authentication-provider> <password-encoder ref="bcrypt"/> <jdbc-user-service id="jdbcuserservice" data-source-ref="datasource" users-by-username-query="select username, password, isactive enabled users username=?" authorities-by-username-query="select u.username, r.role users u, roles r, role_users ur u.id=ur.id_user , r.id=ur.id_role , u.username=?" /> </authentication-provider> </authentication-manager> <beans:bean id="allproperties" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <beans:property name="locations"> <beans:list> <!-- default location inside war file --> <beans:value>classpath:database.properties</beans:value> </beans:list> </beans:property> <beans:property name="ignoreresourcenotfound" value="true" /> </beans:bean>
dispatcher-servlet.xml
<annotation-driven /> <task:annotation-driven /> <context:component-scan base-package="orange.sympa.portail_hubdata" /> <resources mapping="/resources/**" location="/resources/" /> <view-controller path="/" view-name="index" /> <beans:bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <beans:property name="viewclass" value="org.springframework.web.servlet.view.jstlview" /> <beans:property name="prefix" value="/web-inf/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <beans:bean id="allproperties" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <beans:property name="locations"> <beans:list> <!-- default location inside war file --> <beans:value>classpath:database.properties</beans:value> <beans:value>classpath:app.properties</beans:value> </beans:list> </beans:property> <beans:property name="ignoreresourcenotfound" value="true" /> </beans:bean> <beans:bean id="messagesource" class="org.springframework.context.support.reloadableresourcebundlemessagesource"> <beans:property name="basename" value="classpath:messages" /> <beans:property name="defaultencoding" value="utf-8" /> </beans:bean> <!-- [v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v] --> <!-- [v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v] --> <!-- [v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v] --> <beans:bean id="datasourcehhd" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <beans:property name="driverclassname" value="${jdbc.postgresql.hhd.driverclassname}" /> <beans:property name="url" value="${jdbc.postgresql.hhd.url}" /> <beans:property name="username" value="${jdbc.postgresql.hhd.username}" /> <beans:property name="password" value="${jdbc.postgresql.hhd.password}" /> </beans:bean> <beans:bean id="sessionfactoryhhd" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <beans:property name="datasource" ref="datasourcehhd" /> <beans:property name="annotatedclasses"> <beans:list> <beans:value>orange.sympa.portail_hubdata.beans.user</beans:value> <beans:value>orange.sympa.portail_hubdata.beans.role</beans:value> <beans:value>orange.sympa.portail_hubdata.beans.supervisionqueue</beans:value> <beans:value>orange.sympa.portail_hubdata.beans.supervisionqueueuser</beans:value> <beans:value>orange.sympa.portail_hubdata.beans.supervisionqueueapp</beans:value> </beans:list> </beans:property> <beans:property name="hibernateproperties"> <beans:props> <beans:prop key="hibernate.dialect">${jdbc.postgresql.hhd.dialect}</beans:prop> <beans:prop key="hibernate.show_sql">true</beans:prop> <beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop> </beans:props> </beans:property> </beans:bean> <beans:bean id="transactionmanagerhhd" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <beans:property name="sessionfactory" ref="sessionfactoryhhd" /> </beans:bean> <tx:annotation-driven transaction-manager="transactionmanagerhhd"/> <!-- [^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^] --> <!-- [^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^] --> <!-- [^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^] --> <!-- [v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v] --> <!-- [v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v] --> <!-- [v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v] --> <!-- hibernate 4 sessionfactory bean definition --> <beans:bean id="datasourcekpi" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close" > <beans:property name="driverclassname" value="${jdbc.postgresql.kpi.driverclassname}" /> <beans:property name="url" value="${jdbc.postgresql.kpi.url}" /> <beans:property name="username" value="${jdbc.postgresql.kpi.username}" /> <beans:property name="password" value="${jdbc.postgresql.kpi.password}" /> </beans:bean> <beans:bean id="sessionfactorykpi" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <beans:property name="datasource" ref="datasourcekpi" /> <beans:property name="annotatedclasses"> <beans:list> </beans:list> </beans:property> <beans:property name="hibernateproperties"> <beans:props> <beans:prop key="hibernate.dialect">${jdbc.postgresql.kpi.dialect}</beans:prop> <beans:prop key="hibernate.show_sql">true</beans:prop> <beans:prop key="hibernate.hbm2ddl.auto">none</beans:prop> </beans:props> </beans:property> </beans:bean> <tx:annotation-driven transaction-manager="transactionmanagerkpi"/> <beans:bean id="transactionmanagerkpi" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <beans:property name="sessionfactory" ref="sessionfactorykpi" /> </beans:bean> <!-- [^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^] --> <!-- [^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^] --> <!-- [^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^] --> <!-- [v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v] --> <!-- [v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v] --> <!-- [v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v][v] --> <!-- hibernate 4 sessionfactory bean definition --> <beans:bean id="datasourceoozie" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close" > <beans:property name="driverclassname" value="${jdbc.postgresql.oozie.driverclassname}" /> <beans:property name="url" value="${jdbc.postgresql.oozie.url}" /> <beans:property name="username" value="${jdbc.postgresql.oozie.username}" /> <beans:property name="password" value="${jdbc.postgresql.oozie.password}" /> </beans:bean> <beans:bean id="sessionfactoryoozie" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <beans:property name="datasource" ref="datasourceoozie" /> <beans:property name="annotatedclasses"> <beans:list> <beans:value>orange.sympa.portail_hubdata.beans.workflowjobs</beans:value> </beans:list> </beans:property> <beans:property name="hibernateproperties"> <beans:props> <beans:prop key="hibernate.dialect">${jdbc.postgresql.oozie.dialect}</beans:prop> <beans:prop key="hibernate.show_sql">true</beans:prop> <beans:prop key="hibernate.hbm2ddl.auto">none</beans:prop> </beans:props> </beans:property> </beans:bean> <tx:annotation-driven transaction-manager="transactionmanageroozie"/> <beans:bean id="transactionmanageroozie" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <beans:property name="sessionfactory" ref="sessionfactoryoozie" /> </beans:bean> <!-- [^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^] --> <!-- [^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^] --> <!-- [^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^][^] -->
i wanted use lazy access database in jsp, why added block in web.xml
<filter> <filter-name>hibernatefilter</filter-name> <filter-class> org.springframework.orm.hibernate4.support.opensessioninviewfilter </filter-class> <init-param> <param-name>sessionfactorybeanname</param-name> <param-value>sessionfactoryhhd</param-value> </init-param> </filter> <filter-mapping> <filter-name>hibernatefilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
when want access page, exception : org.springframework.beans.factory.nosuchbeandefinitionexception: no bean named 'sessionfactoryhhd' defined
the bean sessionfactoryhhd defined in dispatcher-servlet.xml
can me ? please ?
Comments
Post a Comment