struts2+hibernate+spring
来源:互联网 发布:erp开源软件 编辑:程序博客网 时间:2024/05/23 19:18
1添加jar包(hibernate+其他jar包)
2修改applicationContext配置文件,通过spring容器管理hibernate
<!--配置数据源 dataSource-->
<beanid="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<propertyname="url"value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<propertyname="username"value="scott"></property>
<propertyname="password"value="tiger"></property>
<propertyname="driverClassName"value="oracle.jdbc.driver.OracleDriver"></property>
</bean>
<!-- 配置sessionFactory-->
<beanid="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<propertyname="dataSource">
<refbean="dataSource"/>
</property>
<!-- 读取hibernate配置文件-->
<propertyname="configLocation"value="classpath:hibernate.cfg.xml"/>
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<propkey="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- 映射文件 (也可以写在hibernate.cfg.xml配置文件中)-->
<propertyname="mappingResources">
<list>
<value>vo/emp.hbm.xml</value>
</list>
</property>
</bean>
3创建hibernate.cfg.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEhibernate-configuration PUBLIC
"-//Hibernate/HibernateConfiguration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<propertyname="current_session_context_class">thread</property>
<property name="connection.characterEncoding">UTF-8</property>
</session-factory>
</hibernate-configuration>
4写dao层
配置连接池
注意:如果使用的是Spring3.2.*与Hibernate4.3.*会有版本不兼容的问题
<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">
<propertyname="driverClass"value="oracle.jdbc.driver.OracleDriver">
</property>
<propertyname="jdbcUrl"value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<propertyname="user"value="scott"/>
<propertyname="password"value="tiger"/>
<propertyname="minPoolSize"value="10"/>
<propertyname="maxPoolSize"value="100"/>
<propertyname="maxIdleTime"value="1800"/>
<propertyname="acquireIncrement"value="3"/>
<propertyname="maxStatements"value="1000"/>
<propertyname="initialPoolSize"value="10"/>
<propertyname="idleConnectionTestPeriod"value="60"/>
<propertyname="acquireRetryAttempts"value="30"/>
<propertyname="breakAfterAcquireFailure"value="true"/>
<propertyname="testConnectionOnCheckout"value="false"/>
</bean>
配置事物
修改applicationContext.xml 添加
<!--配置事务管理 -->
<beanid="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<propertyname="sessionFactory"ref="sessionFactory"/>
</bean>
<!--配置事务增强-->
<tx:adviceid="txAdvice"transaction-manager="transactionManager">
<tx:attributes>
<tx:methodname="save*"propagation="REQUIRED"/>
<tx:methodname="delete*"propagation="REQUIRED"/>
<tx:methodname="update*"propagation="REQUIRED"/>
<tx:methodname="get*"read-only="true"propagation="NOT_SUPPORTED"/>
<tx:methodname="*"read-only="true"/>
</tx:attributes>
</tx:advice>
<!--aop配置-->
<aop:configexpose-proxy="true">
<aop:pointcutid="pt"expression="execution(*service.*.*(..))"/>
<aop:advisoradvice-ref="txAdvice"pointcut-ref="pt"/>
</aop:config>
注意el中的路径
修改hibernate.cfg.xml
- struts2+hibernate+spring+ftl....
- struts2+hibernate+spring(1)
- struts2+hibernate+spring(2)
- struts2+spring+hibernate分页
- struts2+spring+hibernate
- struts2+hibernate+spring整合
- struts2 spring hibernate 整合
- struts2+spring+jpa(hibernate)
- Spring struts2 hibernate 整合
- Struts2+spring+hibernate框架
- struts2,spring,ibatis,hibernate
- spring+hibernate+struts2
- struts2+hibernate+spring
- struts2+spring+hibernate实例
- struts2+spring+hibernate整合
- struts2+hibernate+spring配置文件
- Struts2,Spring,Hibernate优缺点
- Struts2+Hibernate+Spring配置
- 正则表达式的思维导图解读
- java web 发送邮件
- Android 解决键盘把布局顶上去的冲突的问题
- 时间戳转日期
- 【工具类】常用操作Excel
- struts2+hibernate+spring
- 期盼中求出起点到终点的最小步数
- mInflater.inflate(R.layout.item_express, null); 高度失效
- [Travel]湖南长沙适合一日游的项目
- Phoenix的安装及JDBC访问
- opencv中SiftDescriptorExtractor所做的SIFT特征向量提取工作简单分析
- 编译open infrastructure platform
- Oracle报错,ORA-28001: 口令已经失效解决方法
- 数据结构实验之串三:KMP应用