• Spring.net 容器注入是替换(后处理器appConfigPropertyHolder)


    1.定义节点
    下面两个都定义为键值对
    <section name="DaoConfiguration" type="System.Configuration.NameValueSectionHandler"/>
    <section name="DatabaseConfiguration" type="System.Configuration.NameValueSectionHandler"/>
    
     <DaoConfiguration>
    The IoC container
    Spring Framework (Version 1.3.2) 68
     <add key="maxResults" value="1000"/>
     </DaoConfiguration>
    
     <DatabaseConfiguration>
     <add key="connection.string" value="dsn=MyDSN;uid=sa;pwd=myPassword;"/>
     </DatabaseConfiguration>
    
    2.应用替换
    <objects xmlns="http://www.springframework.net"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.net
     http://www.springframework.net/xsd/spring-objects.xsd" >
    
     <object name="productDao" type="DaoApp.SimpleProductDao, DaoApp ">
     <property name="maxResults" value="${maxResults}"/>
     <property name="dbConnection" ref="myConnection"/>
     </object>
    
     <object name="myConnection" type="System.Data.Odbc.OdbcConnection, System.Data">
     <property name="connectionstring" value="${connection.string}"/>
     </object>
    <!--用于spring容器的注时替换,后处理器-->
     <object name="appConfigPropertyHolder"
     type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
     <property name="configSections">
     <value>DaoConfiguration,DatabaseConfiguration</value>
     </property>
    
     </object>
    </objects>
     第二种方法,spring环境变量模式
    <object name="appConfigPropertyHolder"
     type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
     <property name="configSections" value="DaoConfiguration,DatabaseConfiguration"/>
     <property name="EnvironmentVariableMode" value="Override"/>
     </object>
    </objects>
    <configuration>
    The IoC container
    Spring Framework (Version 1.3.2) 70
     <configSections>
     <sectionGroup name="spring">
     <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
     </sectionGroup>
     <section name="DaoConfigurationOverride" type="System.Configuration.NameValueSectionHandler"/>
     </configSections>
     <DaoConfigurationOverride>
     <add key="productDao.maxResults" value="1000"/>
     </DaoConfigurationOverride>
    
     <spring>
     <context>
     <resource uri="assembly://DaoApp/DaoApp/objects.xml"/>
     </context>
     </spring>
    </configuration>
    之后也只差应用了
    <objects xmlns="http://www.springframework.net"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/springobjects.xsd"
    >
     <object name="productDao" type="PropPlayApp.SimpleProductDao, PropPlayApp " >
     <property name="maxResults" value="2000"/>
     <property name="dbConnection" ref="myConnection"/>
     <property name="log" ref="daoLog"/>
     </object>
    
     <object name="daoLog" type="Spring.Objects.Factory.Config.LogFactoryObject, Spring.Core">
     <property name="logName" value="DAOLogger"/>
     </object>
    
     <object name="myConnection" type="System.Data.Odbc.OdbcConnection, System.Data">
     <property name="connectionstring">
     <value>dsn=MyDSN;uid=sa;pwd=myPassword;</value>
     </property>
     </object>
     <object name="appConfigPropertyOverride" type="Spring.Objects.Factory.Config.PropertyOverrideConfigurer,
     Spring.Core">
     <property name="configSections">
     <value>DaoConfigurationOverride</value>
     </property>
     </object>
    </objects>
  • 相关阅读:
    Ubuntu 16.04实现SSH无密码登录/免密登录/自动登录(ssh-keygen/ssh-copy-id)
    简单理解Linux的Loopback接口
    iptables为什么需要增加loopback回环的规则
    [ASP.NET Core 3框架揭秘] 依赖注入[10]:与第三方依赖注入框架的适配
    [ASP.NET Core 3框架揭秘] 依赖注入[9]:实现概述
    [ASP.NET Core 3框架揭秘] 依赖注入[8]:服务实例的生命周期
    [ASP.NET Core 3框架揭秘] 依赖注入[7]:服务消费
    [ASP.NET Core 3框架揭秘] 依赖注入[6]:服务注册
    [ASP.NET Core 3框架揭秘] 依赖注入[5]: 利用容器提供服务
    AOP框架Dora.Interception 3.0 [5]: 基于策略的拦截器注册方式
  • 原文地址:https://www.cnblogs.com/kexb/p/5920539.html
Copyright © 2020-2023  润新知