SSH Web Demo Spring 配置 AOP

最近闲来没事 最近封装了一下SSH框架 的一些配置 但具体原来还在理解当中 包括横切面 点切 事物管理的配置
<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://127.0.0.1:3306/test"/>
    <property name="user" value="root"/>
    <property name="password" value="123456"/>
    <property name="minPoolSize" value="10"/>
    <!--连接池中保留的最大连接数。Default: 15 -->
    <property name="maxPoolSize" value="100"/>
    <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
    <property name="maxIdleTime" value="60"/>
    <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
    <property name="acquireIncrement" value="3"/>
    <property name="maxStatements" value="1000"/>
    <property name="initialPoolSize" value="10"/>
    <!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
    <property name="idleConnectionTestPeriod" value="30"/>
    <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
    <property name="acquireRetryAttempts" value="30"/>
    <property name="breakAfterAcquireFailure" value="true"/>
    <property name="testConnectionOnCheckout" value="false"/>
</bean>

<bean id="hibernateTransactionManager"
      class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 配置事务管理器 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置事务通知 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
        <tx:method name="add*" propagation="REQUIRED"/>
        <tx:method name="insert*" propagation="REQUIRED"/>
        <tx:method name="update*" propagation="REQUIRED"/>
        <tx:method name="delete*" propagation="REQUIRED" />
        <tx:method name="select*" read-only="true"/>
        <tx:method name="find*" read-only="true"/>
        <tx:method name="get*" read-only="true"/>
        <tx:method name="query*" read-only="true"/>
    </tx:attributes>
</tx:advice>
<!-- 配置aop -->
<aop:config proxy-target-class="true">
    <aop:pointcut expression="execution(* com.demo.Service..*(..))" id="pointcut"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>
</aop:config>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource"/>
    </property>
    <property name="annotatedClasses">
        <list>
            <value>com.demo.Entity.Detai</value>
            <value>com.demo.Entity.Student</value>
            <value>com.demo.Entity.Users</value>
        </list>
    </property>
    这里会有问题 下面有注释
    <property name="hibernateProperties">
        <props>
            <prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <!--添加此句报异常:
            在spring的类LocalSessionFactoryBean源码,
            方法buildSessionFactory中将hibernate.current_session_context_class设为org.springframework.orm.hibernate5.SpringSessionContext
            <prop key="hibernate.current_session_context_class">thread</prop>
             -->
            <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>
        </props>
    </property>
</bean>
hibernate4.0 有很多不支持。。封装的时候会出现各种classnotfound的问题 
具体是添加一个 aspectjweaver.jar 的包 才将错误改掉


写得超级简单 demo就不上传了。主要记录一下是怎么配置成功的。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值