Spring.Net学习笔记(八)-设置配置文件参数

一、开发环境

VS2013

.netframework4.5

spring.net1.3.1

二、项目结构

三、开发过程

1.编写Person类

  1 namespace SpringNetConfigArg
  2 {
  3     public class Person
  4     {
  5         public string UserName { get; set; }
  6     }
  7 }

2.配置App.config文件

  1 <?xml version="1.0" encoding="utf-8" ?>
  2 <configuration>
  3   <configSections>
  4     <sectionGroup name="spring">
  5       <section name="context" type="Spring.Context.Support.ContextHandler,Spring.Core"/>
  6       <section name="objects" type="Spring.Context.Support.DefaultSectionHandler,Spring.Core"/>
  7     </sectionGroup>
  8     <section name="databaseSettings" type="System.Configuration.NameValueSectionHandler"/>
  9   </configSections>
 10   <!--配置参数-->
 11   <databaseSettings>
 12     <add key="db.datasource" value="."/>
 13     <add key="db.user" value="sa"/>
 14     <add key="db.password" value="123456"/>
 15     <add key="db.database" value="CIS"/>
 16   </databaseSettings>
 17
 18   <spring>
 19     <context>
 20       <resource uri="config://spring/objects"></resource>
 21     </context>
 22     <objects>
 23       <object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer,Spring.Core">
 24         <property name="ConfigSections" value="databaseSettings"></property>
 25       </object>
 26       <!--使用参数-->
 27       <object id="person" type="SpringNetConfigArg.Person,SpringNetConfigArg">
 28         <property name="UserName" value="${db.user}"></property>
 29       </object>
 30     </objects>
 31   </spring>
 32   <startup>
 33     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
 34   </startup>
 35 </configuration>

3.控制台代码

  1 namespace SpringNetConfigArg
  2 {
  3     class Program
  4     {
  5         static void Main(string[] args)
  6         {
  7             IApplicationContext context = ContextRegistry.GetContext();
  8             Person person = context.GetObject("person") as Person;
  9             Console.WriteLine(person.UserName);
 10
 11             Console.ReadKey();
 12         }
 13     }
 14 }

时间: 2024-12-11 07:51:52

Spring.Net学习笔记(八)-设置配置文件参数的相关文章

Spring MVC 学习笔记(二):@RequestMapping用法详解

一.@RequestMapping 简介 在Spring MVC 中使用 @RequestMapping 来映射请求,也就是通过它来指定控制器可以处理哪些URL请求,相当于Servlet中在web.xml中配置 <servlet>     <servlet-name>servletName</servlet-name>     <servlet-class>ServletClass</servlet-class> </servlet>

马哥学习笔记八——LAMP编译安装之PHP及xcache

1.解决依赖关系: 请配置好yum源(可以是本地系统光盘)后执行如下命令: # yum -y groupinstall "X Software Development" 如果想让编译的php支持mcrypt扩展,此处还需要下载如下两个rpm包并安装之: libmcrypt-2.5.7-5.el5.i386.rpm libmcrypt-devel-2.5.7-5.el5.i386.rpm 2.编译安装php-5.4.13 首先下载源码包至本地目录. # tar xf php-5.4.13

Sharepoint2013搜索学习笔记之设置业务数据内容源(六)

Sharepoint搜索爬网组件支持爬Business Data Connectivity Service 承载的外部数据,关于Business Data Connectivity Service设置外部数据源,详请请参考:如何:在 SharePoint 2013 中为 SQL Server 创建外部内容类型,爬网设置步骤如下: 第一步,进入管理中心,点击管理应用程序,点击search service 应用程序进入到搜索管理配置页面,点击内容源 第二步,点击新建内容源,给内容源命名,在爬网内容类

[转]Spring MVC 学习笔记 json格式的输入和输出

Spring mvc处理json需要使用jackson的类库,因此为支持json格式的输入输出需要先修改pom.xml增加jackson包的引用 <!-- json --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-lgpl</artifactId> <version>1.8.1</version>

Spring视频学习笔记(二)

Spring视频学习笔记(二) XML配置里的Bean自动装配(三个来测试实现) /** * Person类 * */ public class Person { private String name; private Address address; private Car car; public String getName() { return name; } public void setName(String name) { this.name = name; } public Ad

Spring Batch学习笔记二

此系列博客皆为学习Spring Batch时的一些笔记: Spring Batch的架构 一个Batch Job是指一系列有序的Step的集合,它们作为预定义流程的一部分而被执行: Step代表一个自定义的工作单元,它是Job的主要构件块:每一个Step由三部分组成:ItemReader.ItemProcessor.ItemWriter:这三个部分将执行在每一条被处理的记录上,ItemReader读取每一条记录,然后传递给ItemProcessor处理,最后交给ItemWriter做持久化:It

[Spring MVC]学习笔记--DispatcherServlet

在上一篇我们介绍了Servlet,这一篇主要来看一下MVC中用到的DispatcherServlet(继承自HttpServlet). 1. DispatcherServlet在web.xml中被声明. <web-app> <servlet> <servlet-name>example</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet&l

Spring Batch学习笔记三:JobRepository

此系列博客皆为学习Spring Batch时的一些笔记: Spring Batch Job在运行时有很多元数据,这些元数据一般会被保存在内存或者数据库中,由于Spring Batch在默认配置是使用HSQLDB,也就是说在Job的运行过程中,所有的元数据都被储存在内存中,在Job结束后会随着进程的结束自动消失:在这里我们推荐配置JobRepository去使用MySQL. 在这种情况下,Spring Batch在单次执行或者从一个执行到另外一个执行的时候会使用数据库去维护状态,Job执行的信息包

iOS学习笔记(八)——iOS网络通信http之NSURLConnection

转自:http://blog.csdn.net/xyz_lmn/article/details/8968182 移动互联网时代,网络通信已是手机终端必不可少的功能.我们的应用中也必不可少的使用了网络通信,增强客户端与服务器交互.这一篇提供了使用NSURLConnection实现http通信的方式. NSURLConnection提供了异步请求.同步请求两种通信方式. 1.异步请求 iOS5.0 SDK NSURLConnection类新增的sendAsynchronousRequest:queu