sping 一些使用

<!-- 组件扫描 -->
<context:component-scan base-package="com.lwp" /> 

<!-- 分散配置 -->
<context:property-placeholder location="classpath:jdbc.properties"/>

<!-- 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverclass}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />

<property name="maxPoolSize" value="${c3p0.pool.size.max}" />
<property name="minPoolSize" value="${c3p0.pool.size.min}" />
<property name="initialPoolSize" value="${c3p0.pool.size.ini}" />
<property name="acquireIncrement" value="${c3p0.pool.size.increment}" />
</bean>

<!-- 本地会话工厂bean,spring整合hibernate的核心入口 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 指定hibernate配置文件 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>

<!-- 事务管理器,在service层面上实现事务管理,而且达到平台无关性 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 配置事务通知 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT" />
<tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT" />
<tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT" />
<tx:method name="batch*" propagation="REQUIRED" isolation="DEFAULT" />
<tx:method name="new*" propagation="REQUIRED" isolation="DEFAULT" />

<tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>
<tx:method name="load*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>
<tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>

<tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" />
</tx:attributes>
</tx:advice>

<!-- aop事务配置 -->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* *..*Service*.*(..))"/>
   
  <!--  <aop:aspect id="LuceneAspect" ref="luceneTranslation">  
           配置com.spring.service包下所有类或接口的所有方法  
           <aop:pointcut id="businessService" expression="execution(* *..*BrandService*.delete(..))
                                                         or execution(* *..*BrandService*.save(..)) 
                                                         or execution(* *..*BrandService*.update(..))  " />  
           <aop:after pointcut-ref="businessService" method="doAfter"/>  
           <aop:after-throwing pointcut-ref="businessService" method="doThrowing" throwing="ex"/>  
            </aop:aspect>   -->
</aop:config> 

<!-- <bean id="luceneTranslation" class="com.lwp.lucene.LuceneTranslation" />

-->
 
 
    <!-- 定时备份 -->
<!-- <bean name="dbBakRestoreTask" class="com.lwp.task.DbBakRestoreTask" />


    <bean id="methodInvokingJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
       <property name="targetObject">
           <ref bean="dbBakRestoreTask" />
       </property>
       <property name="targetMethod">
           <value>SayHello</value>
       </property>
    </bean>
    配置触发器
    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        这里不可以直接在属性jobDetail中引用taskJob,因为他要求的是一个jobDetail类型的对象,所以我们得通过MethodInvokingJobDetailFactoryBean来转一下
       <property name="jobDetail">
           <ref bean="methodInvokingJobDetail" />
       </property>
       每天的0:00触发,具体说明见附录
       <property name="cronExpression">
           <value>0 0 0 * * ?</value>
       </property>


    </bean>


    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
       添加触发器
       <property name="triggers">
           <list>
              <ref local="cronTrigger" />
           </list>
       </property>
    </bean> -->
发布了20 篇原创文章 · 获赞 2 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/u010947651/article/details/48436389