`

Spring 配置之 PropertyPlaceholderConfigurer

 
阅读更多

 

<!-- ============= GENERAL DEFINITIONS ============= -->

<!-- Configurer that replaces ${...} placeholders with values from a properties file -->

<!-- (in this case, JDBC-related settings for the dataSource definition below) -->

<bean id="propertyConfigurer"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="location">

<value>classpath:spring/jdbc-oracle.properties</value>

</property>

</bean>

<!--PropertyPlaceholderConfigurer

A property resource configurer that resolves placeholders in bean property values of context definitions. It pulls values from a properties file into bean definitions

->

 

<!-- ============== RESOURCE DEFINITIONS ========= -->

<!-- Local DataSource that works in any environment -->

<bean id="dataSource"

class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName">

<value>${jdbc.driverClassName}</value>

</property>

<property name="url">

<value>${jdbc.url}</value>

</property>

<property name="username">

<value>${jdbc.username}</value>

</property>

<property name="password">

<value>${jdbc.password}</value>

</property>

</bean>

<!--DriverManagerDataSource

Simple implementation of the standard JDBC DataSource interface, configuring the plain old JDBC DriverManager via bean properties, and returning a new Connection from every getConnection call. 

NOTE: This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call

-->

 

   <!-- Spring iBatis SqlMapClient -->

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">

        <property name="configLocation" value="classpath:ibatis/sql-map-config.xml" />

         <property name="dataSource" ref="dataSource"></property>

    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource"></property>

    </bean>

    <bean id="transactionIterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">

     <property name="transactionManager" ref="transactionManager"></property>

     <property name="transactionAttributes">

      <props>

       <prop key="insert*">PROPAGATION_REQUIRED</prop>

       <prop key="add*">PROPAGATION_REQUIRED</prop>

       <prop key="find*,get*">PROPAGATION_REQUIRED,readOnly</prop>

       <prop key="*">PROPAGATION_REQUIRED</prop>

      </props>

     </property>

    </bean>

    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">

     <property name="beanNames">

      <list>

       <value>*Service</value>

      </list>

     </property>

     <property name="interceptorNames">

      <list>

       <value>transactionIterceptor</value>

      </list>

     </property>

    </bean>

</beans>

分享到:
评论

相关推荐

    Spring PropertyPlaceholderConfigurer配置文件加载器集成ZooKeeper来实现远程配置读取

    5. 在Spring配置文件中声明`ZooKeeperPropertyPlaceholderConfigurer`,并配置ZooKeeper连接信息。 6. 使用`@Value`注解或其他方式引用配置,Spring会在启动时从ZooKeeper读取并注入值。 这个过程涉及到的知识点...

    Spring中PropertyPlaceholderConfigurer的使用

    使用 PropertyPlaceholderConfigurer 需要首先在 Spring 配置文件中定义一个 bean,例如: ```xml &lt;bean id="propertyConfigurerForAnalysis" class="org.springframework.beans.factory.config....

    Spring属性占位符PropertyPlaceholderConfigurer的使用

    在Spring框架中,属性占位符`PropertyPlaceholderConfigurer`是一个重要的工具,用于处理配置文件中的属性值引用。它使得我们可以在XML配置文件中使用占位符`${...}`来引用外部属性文件中的值,从而使应用配置更加...

    Spring如何使用PropertyPlaceholderConfigurer读取文件

    Spring框架中,PropertyPlaceholderConfigurer是一个非常重要的组件,它可以帮助我们读取配置文件,实现系统的配置信息统一管理。在大型项目中,我们往往会将配置信息配置在一个cfg.properties文件中,然后在系统...

    spring 配置文件 归类

    本篇文章将深入探讨Spring配置文件中的归类,主要包括IOC(Inversion of Control,控制反转)和AOP(Aspect-Oriented Programming,面向切面编程)两个重要概念。 ### 1. IOC (控制反转) IOC是Spring的核心特性,...

    Spring动态加载配置文件

    要实现动态加载配置文件,我们可以利用Spring的`PropertyPlaceholderConfigurer`或`@PropertySource`注解。`PropertyPlaceholderConfigurer`是Spring早期版本中处理属性文件的工具,而`@PropertySource`则是从Spring...

    spring配置文件

    《Spring配置文件详解》 Spring框架的核心之一就是其配置文件,它是实现依赖注入(Dependency Injection,简称DI)的关键。配置文件通常以XML格式存在,用于定义bean及其相互依赖关系,从而构建应用程序的组件模型...

    关于spring系统中多系统的配置

    在Spring框架中,`PropertyPlaceholderConfigurer`是一种特殊的Bean,它被用来处理Spring配置文件中的占位符(placeholder),并将它们替换为具体的值。这些值通常来自外部的属性文件,如`.properties`或`.xml`等。...

    SPRING:bean配置properties

    在Spring框架中,Bean的配置与管理是其核心功能之一,而通过`PropertyPlaceholderConfigurer`进行属性占位符的配置则是实现动态配置的关键技术。本文将深入解析如何利用`PropertyPlaceholderConfigurer`进行bean配置...

    Spring项目中怎么配置log4j

    在Spring项目中,我们可以使用Spring的`PropertyPlaceholderConfigurer`来加载外部化的log4j配置,这样在不同环境中可以使用不同的配置文件。在Spring的配置文件`applicationContext.xml`中添加以下代码: ```xml ...

    Spring配置加密方案收集.pdf

    在Spring配置中,我们可以使用`PropertyPlaceholderConfigurer`或`PropertiesFactoryBean`来加载加密后的属性文件,并在运行时调用`EncryptPropertyFile`类的解密方法,确保Spring在初始化时能够正确解析和加载加密...

    spring配置两个数据

    ### Spring配置两个数据源 #### 核心概念解析 **数据源(DataSource)**:在Java中,数据源是一个接口,由`javax.sql.DataSource`定义,它用于获取数据库连接。Spring框架通过其灵活的配置机制,可以轻松创建并...

    org.springframework.beans.factory.config.PropertyPlaceholderConfigurer

    `org.springframework.beans.factory.config.PropertyPlaceholderConfigurer` 是Spring框架中的一个重要组件,主要负责处理配置文件中的占位符替换。这个类是Spring在初始化bean时用来解析和注入环境变量或系统属性...

    配置spring

    1. **web.xml中的Spring配置** 在web.xml中,我们需要配置Spring的`ContextLoaderServlet`来初始化Spring容器。这通常通过`&lt;servlet&gt;`标签来完成,其中`servlet-class`是`org.springframework.web.context....

    Spring 配置学习文件

    在Spring框架中,配置文件起着至关重要的作用,它们定义了应用程序的组件以及它们之间的依赖关系。这里有两个主要的配置文件:`applicationContext-database.xml` 和 `applicationContext-pojo.xml`,分别关注于...

    spring2.5 配置VM

    标题“spring2.5配置VM”指的是在Spring框架2.5版本中,如何配置虚拟机参数(Virtual Machine,VM)或者Spring的VM选项。在Spring框架中,VM选项通常指的是在应用启动时传递给Java虚拟机的一系列系统属性,它们可以...

    spring,配置文件从属性文件读取JDBC连接的相关参数

    在Spring配置文件(如`applicationContext.xml`或`beans.xml`)中,我们可以创建一个`Properties` bean来加载`jdbc.properties`: ```xml &lt;bean id="propertyConfigurer" class="org.springframework.beans....

    Spring的log4j以及配置文件

    在Spring框架中,我们可以使用Spring的`PropertyPlaceholderConfigurer`来读取`log4j.properties`文件中的配置,并动态注入到应用中。这允许我们在不重启应用的情况下,通过修改外部的配置文件来调整日志级别和输出...

    Spring3.0 配置文件中加载Properties文件的小例子

    接下来,我们将在Spring的配置文件(如`applicationContext.xml`)中声明一个`PropertyPlaceholderConfigurer` bean,它负责加载并解析Properties文件。配置如下: ```xml class="org.springframework.beans....

    spring配置文件加密方法示例

    一个典型的Spring配置文件(如`applicationContext.xml`)是一个XML文档,它包含Bean的定义,这些定义描述了对象的创建方式、它们之间的依赖关系以及如何初始化和销毁这些对象。当Spring容器启动时,它会读取这些...

Global site tag (gtag.js) - Google Analytics