Spring+hibernate+springmvc 整合(四)

来源:互联网 发布:php mysql增删改查 编辑:程序博客网 时间:2024/06/05 08:38

3、 整合hibernate  a)  

 Web.xml openonesessionInView

<!-- Hibernate Open Session in View Filter--> <filter>  <filter-name>hibernateFilter</filter-name><filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter>     <filter-mapping>  <filter-name>hibernateFilter</filter-name>  <url-pattern>/*</url-pattern> </filter-mapping>  <filter>       b)    Spring  中配置<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">        <property name="driverClassName" value="com.mysql.jdbc.Driver">        </property>        <property name="url"    value="jdbc:mysql://localhost:3306/test_szoa?characterEncoding=utf-8"></property>        <property name="username" value="root"></property>    </bean>    <bean id="sessionFactory"    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">        <property name="dataSource">            <ref bean="dataSource" />        </property>        <property name="hibernateProperties">            <props>                <prop key="hibernate.dialect">                    org.hibernate.dialect.MySQLInnoDBDialect                </prop>                <prop key="hibernate.show_sql">true</prop>            </props>        </property>        <property name="mappingDirectoryLocations">            <list>                <value>classpath:icom/szoa/</value>            </list>        </property><!-- 自动扫描hibernate 注解 -->            <property name="packagesToScan">            <list>                <value>icom.**.domain</value>            </list>        </property>    </bean>


原创粉丝点击