spring 中hibernate配制

document文档document.forms[0]文档中的第一个表单document.forms[0].title文档中的第一个表单的title表单
document.forms[0].title.value文档中的第一个表单的title表单的内容
HttpServletRequest request = ServletActionContext.getRequest();
String ids = request.getParameter("ids");

为了在Action处理过程中可以访问到当前请求HttpServerRequest对象,通俗的说就是request.getParameter可以取到值.
我们可以使用依赖注入机制的接口注入方法.接口注入需要的是已经被实现了的接口。这个接口包含了相应属性的setter,为Action提供值
我做的这个神话网的例子中,有一个action需要request.getParameter取得value,所以我实现了ServletRequestAware接口,同进声明了一个
HttpSerletRequest的属性.看起来好像是线程不安全的,其实在struts2中并没有问题,因为每个请求过来的时候都会产生一个新的Action对象实例,
它并没有和其他请求共享一个对象,所以不需要考虑线程安全问题。
<?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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.demo.cyd" />
<!-- 使用C3P0方式连接数据库-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo" />
<property name="user" value="root" />
<property name="password" value="root" />
<property name="autoCommitOnClose" value="true" />
<property name="checkoutTimeout" value="10000" />
<property name="initialPoolSize" value="10" />
<property name="minPoolSize" value="3" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="30000" />
<property name="acquireIncrement" value="3" />
<property name="maxIdleTimeExcessConnections" value="1800" />
</bean>
<!-- 整合Hibernate操作数据库 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.demo.cyd.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>

<!-- 创建Hibernate操作数据库的模版 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" >
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 使用XML方式配置事物-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="update*" />
<tx:method name="delete*" />
<tx:method name="add*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="bussinessService" expression="execution(public * com.demo.cyd.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" />
</aop:config>
<!-- 配置事物所使用的数据库连接方式 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值