hibernatge如何指定jdbc配置文件呢?
jdbc配置文件型如:
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://182.92.94.71:3306/test jdbc.username=root jdbc.password=123456
在hibernate的配置文件中有两种方式指定jdbc配置文件
方式一:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath:jdbc.properties</value> </property> </bean>
方式二:
<context:property-placeholder location="classpath:jdbc.properties" />
beans.xml的完整内容如下:
<?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" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd" default-lazy-init="false"> <context:annotation-config /> <context:component-scan base-package="com,oa" ></context:component-scan> <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!--initialSize: 初始化连接--> <property name="initialSize" value="1"/> <!--maxActive: 最大连接数量--> <property name="maxActive" value="2"/> </bean> <!-- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath:jdbc.properties</value> </property> </bean> --> <context:property-placeholder location="classpath:jdbc.properties" /> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!--<property name="packagesToScan"> <list> <value>com.pass.bean</value> </list> </property> --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQL5Dialect </prop> <!-- org.hibernate.dialect.PostgreSQLDialect --> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">none</prop> <prop key="hibernate.use_sql_comments">true</prop> <prop key="current_session_context_class">thread</prop> <prop key="javax.persistence.validation.mode">none</prop> </props> </property> <property name="packagesToScan"> <list> <value>com.entity</value> <value>oa.entity</value> </list> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 事务的注解,如 @Transactional(readOnly=true) <tx:annotation-driven transaction-manager="txManager" /> --> <aop:config> <aop:pointcut id="bussinessService" expression="execution(public * oa.dao..*.*(..)) ||execution(public * com.dao..*.*(..)) || execution(public * com.common.dao.generic..*.*(..))" /> <aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="count*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="test*" read-only="true" /> <tx:method name="is*" read-only="true" /> <tx:method name="show*" read-only="true" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="edit*" propagation="REQUIRED" /> <tx:method name="set*" propagation="REQUIRED" /> <tx:method name="change*" propagation="REQUIRED" /> <tx:method name="to*" propagation="REQUIRED" /> <tx:method name="modify*" propagation="REQUIRED" /> <tx:method name="verify*" read-only="true" /> <tx:method name="list*" read-only="true" /> </tx:attributes> </tx:advice> <!-- 支持上传文件 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> </beans>
相关推荐
XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. JNDI绑定的SessionFactory 3.8.3. 在JTA环境下使用Current Session context (当前session上下文)管理 3.8.4. JMX部署 4. 持久化类...
请按照相应的配置文件修改即可。 -- dbcp还要再试试,才知道是否支持,理论是支持的。 4. 编辑spy.properties文件,把JDBC Driver Class Name作为RealDriverName的值,其它的属性一般不用指定. 5. 把spy....
12.6.16 编写Spring和Hibernate的配置文件spring-config.xml 12.6.17 编写web.xml 12.6.18 验证示例 12.7 小结 第四篇 J2EE项目案例精选 第十三章 网上调查系统 13.1 系统概述 13.2 需求分析 13.2.1 系统用例图 ...
3.7. XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. JNDI绑定的SessionFactory 3.8.3. 在JTA环境下使用Current Session context (当前session上下文)管理 3.8.4. JMX部署 4. 持久化...
使用方法:直接在hibernate配置文件中指定如下语句即可 <property name="hibernate.dialect">SQLiteUtil.SQLiteDialect 此包使用的hibernate版本为4.3.5-Final,sqlite jdbc驱动版本为sqlite-jdbc-3.7.2.jar.需要...
建立最简单的项目基础结构:Board/User/Article三个类,包含最基本的配置文件。同时,在这一步中,建立测试类,刻画项目各个类之间的契约关系。 步骤2: 对文章的种类增加“投票”类型,展示对多型的处理。 步骤3: ...
3.1 创建Hibernate的配置文件 3.2 创建持久化类 3.3 创建数据库Schema 3.4 创建对象-关系映射文件 3.4.1 映射文件的文档类型定义(DTD) 3.4.2 把Customer持久化类映射到CUSTOMERS表 3.5 通过...
12.6.16 编写Spring和Hibernate的配置文件spring-config.xml 12.6.17 编写web.xml 12.6.18 验证示例 12.7 小结 第四篇 J2EE项目案例精选 第十三章 网上调查系统 13.1 系统概述 13.2 需求分析 13.2.1 系统用例图 ...
1.springMvc 以 location="classpath:*-gourderwa.properties" 装载配置,若修改配置文件名称对应修改此处 2.指定 ehcache.xml 中 diskStore path 存储目录 3.数据库连接配置见 jdbc-hibernate-config-gourderwa....
3.7. XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. JNDI绑定的SessionFactory 3.8.3. 在JTA环境下使用Current Session context (当前session上下文)管理 3.8.4. JMX部署 4. 持久化...
3.7. XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. JNDI绑定的SessionFactory 3.8.3. 在JTA环境下使用Current Session context (当前session上下文)管理 3.8.4. JMX部署 4. 持久化...
12.6.16 编写Spring和Hibernate的配置文件spring-config.xml 12.6.17 编写web.xml 12.6.18 验证示例 12.7 小结 第四篇 J2EE项目案例精选 第十三章 网上调查系统 13.1 系统概述 13.2 需求分析 13.2.1 系统用例图 ...
3.7. XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. JNDI绑定的SessionFactory 3.8.3. 在JTA环境下使用Current Session context (当前session上下文)管理 3.8.4. JMX部署 4. 持久化类...
3)写hibernate所需的配置文件,hibernate.cfg.xml ,Xxxxx.hbm.xml 4)调用hibernate API。 a)使用Configuration对象的buildSessionFactory()方法创建SessionFactory对象。 b)使用SessionFactory对象openSession...
3.7. XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. JNDI绑定的SessionFactory 3.8.3. 在JTA环境下使用Current Session context (当前session上下文)管理 3.8.4. JMX部署 4. 持久化...
3.7. XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. JNDI绑定的SessionFactory 3.8.3. 在JTA环境下使用Current Session context (当前session上下文)管理 3.8.4. JMX部署 4. 持久化...
由于Spring通过代理Hibernate完成数据层的操作,所以原Hibernate的配置文件hibernate.cfg.xml的信息也转移到Spring的配置文件中: 代码 4 Spring中有关Hibernate的配置信息 1. 2. !-- 数据源的配置 //--> 3. ...
按照循序渐进的原则,分为不同的步骤: <br/>步骤1: 建立最简单的项目基础结构:Board/User/Article三个类,包含最基本的配置文件。同时,在这一步中,建立测试类,刻画项目各个类之间的契约关系。 <br...
3.7. XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. JNDI绑定的SessionFactory 3.8.3. JTA和Session的自动绑定 3.8.4. JMX部署 4. 持久化类(Persistent Classes) 4.1. 一个简单的...