使用spring与hibernate实现配置文件

  介绍

这篇文章给大家介绍使用spring与hibernate实现配置文件,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

春整合hibernate有两种方式1,注解方式2,xml方式实现

1,注解方式实现:

applicationContext。xml配置文件:

& lt;及# 63;xml version=?.0”;编码=癠TF-8", # 63;比;   http://www.springframework.org/schema/beans" & lt;豆类xmlns=?   xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance"   xmlns: aop=癶ttp://www.springframework.org/schema/aop"   xmlns: tx=癶ttp://www.springframework.org/schema/tx"   xmlns:上下文=癶ttp://www.springframework.org/schema/context"   xsi: schemaLocation=?   http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd   http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx.xsd   http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop.xsd   http://www.springframework.org/schema/context   ,http://www.springframework.org/schema/context/spring-context.xsd"的在   & lt;上下文:component-scan基础包=癱om.test"/比;   & lt; bean类=皁rg.springframework.beans.factory.config.PropertyPlaceholderConfigurer"祝辞   & lt;属性名=發ocations"祝辞   & lt; list>   & lt; value>类路径:jdbc.properties   & lt;/list>   & lt;/property>   & lt;/bean>   & lt; bean id=癱3p0DataSource"销毁方法=癱lose"   类=癱om.mchange.v2.c3p0.ComboPooledDataSource"比;   & lt;属性名=癲riverClass"https://www.yisu.com/zixun/value=" $ {driverClass} "/>   <属性名=" jdbcUrl " value=" $ {url} "/>   <属性名="用户" value=" $ {user} "/>   <属性名="密码" value=" ${密码}"/>   <属性名=" initialPoolSize " value=" $ {initialPoolSize} "/>   <属性名=" minPoolSize " value=" $ {minPoolSize} "/>   <属性名=" maxPoolSize " value=" $ {maxPoolSize} "/>   <属性名=" maxIdleTime " value=" $ {maxIdleTime} "/>         <属性名=笆菰础眗ef=" c3p0DataSource "/>   <属性名=" packagesToScan ">   <列表>   <价值> com.test.bean   列表>   <道具>   <支撑关键=" hibernate.dialect "> ${方言}   <支撑关键=" hibernate.show_sql "> $ {show_sql}   <支撑关键=" hibernate.format_sql "> $ {format_sql}   <支撑关键=" hibernate.use_sql_commants "> $ {use_sql_comments}   <支撑关键=癮uto”> $ {hbm2ddl.auto}         <属性名=" sessionFactory“ref=" sessionFactory "/>                                       

2. xml方式实现

applicationContext。xml配置:

& lt;及# 63;xml version=?.0”;编码=癠TF-8", # 63;比;   http://www.springframework.org/schema/beans" & lt;豆类xmlns=?   xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance"   xmlns: aop=癶ttp://www.springframework.org/schema/aop"   xmlns: tx=癶ttp://www.springframework.org/schema/tx"   xsi: schemaLocation=? http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd   http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx.xsd   http://www.springframework.org/schema/aop   ,http://www.springframework.org/schema/aop/spring-aop.xsd"的在      & lt; !——让春天去读取指定路径下的资源文件——比;   & lt; bean类=皁rg.springframework.beans.factory.config.PropertyPlaceholderConfigurer"祝辞   & lt;属性名=發ocations"值=https://www.yisu.com/zixun/崩嗦肪?jdbc.properties "/>               <属性名=" driverClass " value=" $ {driverClass} "/>   

使用spring与hibernate实现配置文件