hibrenate及Spring配置

hibrenate配置文件配置MYSQL

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE hibernate-configuration PUBLIC
 3         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 4         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 5 <hibernate-configuration>
 6     <session-factory>
 7             <!-- Database connection settings -->  
 8         <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>  
 9         <property name="connection.url">jdbc:mysql://127.0.0.1:3308/mytest?useUnicode=true&amp;characterEncoding=UTF-8</property>  
10         <property name="connection.username">root</property>
11         <!-- <property name="connection.password"></property> -->  
12   
13         <!-- JDBC connection pool (use the built-in) -->  
14         <property name="connection.pool_size">10</property>  
15         <property name="connection.autocommit">true</property><!-- 自动提交事物需要用到这个 -->
16   
17         <!-- SQL dialect -->  
18         <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>  
19   
20         <!-- Enable Hibernate's automatic session context management -->  
21         <property name="current_session_context_class">thread</property>  
22   
23         <!-- Disable the second-level cache  -->  
24         <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>  
25   
26         <!-- Echo all executed SQL to stdout -->  
27         <property name="show_sql">true</property>  
28   
29         <!-- Drop and re-create the database schema on startup -->  
30         <property name="hbm2ddl.auto">update</property>  
31   
32         <mapping resource="com/sf/sftech/postest/entity/maping/Student.hbm.xml"/>  
33     </session-factory>
34 </hibernate-configuration>
View Code

Maven依赖配置

 1         <dependency>
 2             <groupId>junit</groupId>
 3             <artifactId>junit</artifactId>
 4             <version>3.8.1</version>
 5             <scope>test</scope>
 6         </dependency>
 7         <dependency>
 8             <groupId>org.hibernate</groupId>
 9             <artifactId>hibernate-core</artifactId>
10             <version>3.6.10.Final</version>
11         </dependency>
12         <dependency>
13             <groupId>mysql</groupId>
14             <artifactId>mysql-connector-java</artifactId>
15             <version>5.1.18</version>
16         </dependency>
17         <dependency>
18             <groupId>org.javassist</groupId>
19             <artifactId>javassist</artifactId>
20             <version>3.18.1-GA</version>
21         </dependency>
22         <dependency>
23             <groupId>org.slf4j</groupId>
24             <artifactId>slf4j-nop</artifactId>
25             <version>1.7.7</version>
26         </dependency>
27         <dependency>
28             <groupId>org.springframework</groupId>
29             <artifactId>spring-context</artifactId>
30             <version>4.1.6.RELEASE</version>
31         </dependency>
View Code

Spring的bean配置

1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans     xmlns="http://www.springframework.org/schema/beans"  
3         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
4         xsi:schemaLocation="http://www.springframework.org/schema/beans    
5         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6     <bean id="test" class="com.sf.sftech.postest.entity.Student"></bean>
7 </beans>
View Code

注:在非web项目的情况下,hibrenate的配置文件及Spring的配置文件都应该放在项目的根目录下

转载于:https://www.cnblogs.com/fshimao/p/5180199.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值