當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Dao层系列-4-Hibernate Spring Annotation
生活随笔
收集整理的這篇文章主要介紹了
Dao层系列-4-Hibernate Spring Annotation
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
之前幾篇文章主要是介紹 Hibernate、Hibernate Annotation、Hibernate Spring 集成這篇文章主要是:Hibernate和Spring集成后都使用注解的方式。
Hibernate使用注解進行關系映射,Spring使用注解進行Bean的依賴注入。
Spring的配置如下:
<?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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsd"><!--<context:annotation-config/>--><context:component-scan base-package="com.yaolifei.test"/><context:property-placeholder location="jdbc.properties" /><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}" /> <property name="username" value= "${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="maxActive" value="${jdbc.maxActive}" /> <property name="validationQuery" value="${jdbc.validationQuery}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="packagesToScan" value="com.yaolifei.test.user.domain"/><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop><prop key="hibernate.current_session_context_class">thread</prop><prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.hbm2ddl.auto">update</prop></props></property></bean></beans> 完整代碼請見:http://git.oschina.net/yaolifei/test/tree/master/test-hibernate-spring-annotation
轉載于:https://my.oschina.net/yaolifei/blog/145673
總結
以上是生活随笔為你收集整理的Dao层系列-4-Hibernate Spring Annotation的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: nginx 服务器的学习(1)
- 下一篇: 有点烦,不知道如何开始准备评测师考试?