`
duanyan123
  • 浏览: 12117 次
  • 性别: Icon_minigender_2
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

spring的配置记录

阅读更多
<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-2.5.xsd"
       default-lazy-init="false"
>

<!-- 定义数据源1 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="url" value="jdbc:db2://192.168.61.232:50002/BRMSDB:currentSchema=BILL;"/>
<property name="username" value="brms"/>
<property name="password" value="brms0001"/>
</bean>

<!-- 定义数据源2 -->
<context:property-placeholder location="jdbc.properties"/>
<bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>

<!-- jdbc Template -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dateSource" ref="dateSource"/>
</bean>

<!-- session Factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactory>
<property name="dataSource" ref="dateSource"/>
<property name="packagesToScan">
<list><value>com.*.*.model</value></list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>

<!-- transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransaction">
<property name="dataSource" ref="dateSource"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- dao level: @Component @Controller @Service @Repository -->
<context:component-scan base-package="com.*.*.dao"/>

<!-- service level: @Transaction + @Component、@Controller、@Service、@Repository -->
<context:component-scan base-package="com.*.*.service/>

<!-- 1、基于XML的事务配置方式 -->
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.service..*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- 2、使用注解方式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
0
0
分享到:
评论

相关推荐

    Spring配置文件集合

    7. `spring-aop.xml`: 用于配置Spring的AOP(面向切面编程)相关设置,如定义切面、通知类型等,使得我们可以进行横切关注点的处理,如日志记录、事务管理等。 8. `log4j.xml`: 该文件是Log4j的日志配置,定义了...

    使用Spring配置文件实现AOP

    这篇教程将详细讲解如何通过Spring的配置文件来实现AOP。 一、理解AOP概念 AOP的核心思想是将分散在各个模块中的交叉性代码(如日志、事务处理)抽取出来,形成独立的切面,以便于复用和维护。它提供了一种模块化的...

    Spring的基本配置

    一、Spring配置概述 Spring的配置方式主要有两种:XML配置和Java配置。早期,XML配置是主流,而现在,随着Spring Boot的兴起,Java配置逐渐成为首选,因为它更加简洁和直观。不过,理解XML配置对于学习Spring的基础...

    SpringCloud——分布式配置中心(Spring Cloud Config)

    在微服务架构中,Spring Cloud Config 是一个强大的分布式配置中心,它允许开发人员将应用程序的配置存储在远程仓库中,并且可以在运行时动态地管理和更新这些配置,无需重启应用。这个特性对于大型分布式系统来说...

    大型项目的struts,spring配置文件

    此外,Spring还支持AOP配置,可以定义切面和通知,实现如日志记录、事务管理等横切关注点。 在整合Struts和Spring的过程中,还需要一个名为`struts-spring-plugin.xml`的文件,这是Struts与Spring集成的关键。这个...

    spring配置文件

    本压缩包文件围绕"spring配置文件"展开,旨在帮助用户更好地理解和使用Spring框架的配置。 首先,Spring配置文件通常指的是XML格式的`applicationContext.xml`,这是Spring容器的主配置文件,用于定义bean的实例、...

    spring日志配置为log4j

    总之,将Spring的日志配置为Log4j,涉及到引入Log4j库、编写`log4j.properties`配置文件、以及在Spring配置文件中声明使用Log4j。理解这些步骤和配置项对于优化日志记录,排查问题以及监控系统运行状态至关重要。

    springcloud配置中心个人demo

    可以结合 Spring Boot Actuator 来实现对配置更新的监控和相关日志的记录。 通过这个 "springcloud-config" 压缩包,你可以学习如何设置和使用 SpringCloud Config,理解其核心概念和工作流程,以及如何在 Java ...

    Spring依赖包和配置文件

    二、Spring配置文件 1. **beans.xml**:这是Spring应用中最常见的配置文件,用于定义bean及其依赖关系。在这里,我们可以声明bean的类、属性、初始化方法、依赖注入等。 2. **applicationContext.xml**:此文件通常...

    struct和spring整合的配置

    2. **AOP支持**:Spring的AOP功能可以用于事务管理、日志记录等,使代码更简洁。 3. **测试友好**:由于Action类不直接创建服务对象,可以更方便地进行单元测试。 4. **统一管理**:所有Bean都在Spring容器中统一...

    利用Spring机制记录系统日志

    通过以上介绍,我们可以看出,利用Spring机制记录系统日志是一项涉及AOP、XML配置、日志框架集成等多个方面的任务。正确实施这一机制,能够有效地提升系统的可维护性和稳定性,帮助开发者更好地理解和调试系统。

    spring整合struts2与hibernate核心配置文件

    1. **Spring配置**:设置数据源,创建SessionFactory Bean,配置事务管理器。 2. **Struts2配置**:启用Spring插件,配置Action类为Spring管理的bean。 3. **Hibernate配置**:配置数据库连接信息,定义实体类映射,...

    spring 与 spring mvc 整合 配置讨论

    7. **AOP**:利用Spring的AOP功能,可以实现事务管理、日志记录等功能。例如,使用`@Transactional`注解开启方法级别的事务管理。 8. **源码分析**:深入理解Spring和Spring MVC的源码,有助于优化配置和解决问题。...

    spring 配置文件详解.txt

    ### Spring配置文件详解 #### 一、Spring框架与配置文件的重要性 Spring框架是Java平台上的一个开源框架,它提供了一种轻量级的方式来管理和组织Java应用程序中的组件。Spring框架的核心特性之一是依赖注入...

    Spring之AOP配置文件详解

    ### Spring之AOP配置文件详解 #### 一、前言 在Java开发中,Spring框架因其强大的功能和灵活的配置而被广泛应用于企业级应用的开发。其中,面向切面编程(Aspect Oriented Programming,简称AOP)是Spring框架的...

    spring配置详解

    一、Spring配置文件基础 `applicationContext.xml`是Spring应用上下文的主要配置文件,用于定义bean的实例化、依赖关系以及其行为。在文件中,我们通常会看到如下的基本结构: ```xml &lt;beans xmlns="http://www....

    springboot框架+Mybatis+SpringSecurity+logback 都配置好啦

    Spring Boot的核心理念是“约定优于配置”,这使得开发者能够快速构建可运行的应用程序。在本项目中,Spring Boot与Mybatis、Spring Security和Logback一起被整合,为一个完整的、安全的、日志记录完善的Web应用提供...

    Spring MVC 配置请求的默认处理器.rar

    Spring MVC还允许我们定义拦截器,可以在请求处理前后执行额外的操作,如权限检查、日志记录等。通过`&lt;mvc:interceptors&gt;`配置,可以添加多个拦截器。 7. **异常处理** 可以通过`&lt;exception-handler&gt;`元素定义...

    spring定时任务配置详解.doc

    这里我们将深入讲解如何在Spring中配置和使用定时任务。 首先,Spring提供了两种定时任务的实现方式:`Spring Task` 和 `Quartz Scheduler`。在本例中,我们看到的是使用Quartz Scheduler的例子,这是一个功能强大...

Global site tag (gtag.js) - Google Analytics