1.app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
    </sectionGroup>
  </configSections>

<spring>

<context>
      <resource uri="assembly://FirstSpringNetApp/FirstSpringNetApp/Objects.xml"/>
      <resource uri="config://spring/objects" />
    </context>
    <objects xmlns="http://www.springframework.net"/> <!--必要-->
  </spring>

</configuration>
2.根据app.config设置的object.xml文件 相当于一个工厂
<?xml version="1.0" encoding="utf-8" ?>

<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 id="PersonDao" type="FirstSpringNetApp.PersonDao, FirstSpringNetApp" />
 
</objects>

3.persondao类

namespace FirstSpringNetApp
{
    public class PersonDao
    {
        public override string ToString()
        {
            return "我是PersonDao";
        }
    }
}

4.对象的获取方式的说明 通常我们使用程序集路径

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
using Spring.Core.IO;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;

namespace FirstSpringNetApp
{
    class Program
    {
        static void Main(string[] args)
        {
            AppRegistry();
            XmlSystem();
            Console.ReadLine();
        }

static void AppRegistry()
        {
            IApplicationContext ctx = ContextRegistry.GetContext();
            Console.WriteLine(ctx.GetObject("PersonDao").ToString());
        }

static void XmlSystem()
        {
            string[] xmlFiles = new string[]
            {
                //"file://Objects.xml"  //, 文件名
                "assembly://FirstSpringNetApp/FirstSpringNetApp/Objects.xml"  //程序集
            };
            IApplicationContext context = new XmlApplicationContext(xmlFiles);

IObjectFactory factory = (IObjectFactory)context;
            Console.WriteLine(factory.GetObject("PersonDao").ToString());
        }

static void FileSystem()
        {
            IResource input = new FileSystemResource(@"D:\Objects.xml");  //实际物理路径
            IObjectFactory factory = new XmlObjectFactory(input);
            Console.WriteLine(factory.GetObject("PersonDao").ToString());
        }
    }
}

有时出现spring调用目标异常却束手无策,这里给出一些可能性

1.没有引用相应的dll 如 common.logging.dll common.logging.log4net.dll ,log4net.dll ,spring.core.dll,spring.data.dll,spring.data.nhibernate30.dll ,spring.web.dll,spring.service.dll,Spring.Aop.dll,Spring.Scheduling.Quartz.dll,Quartz.dll,nhibernate.dll

除了这些基本的dll在跟hibernate继承的时候,要引用相应的数据客户端dll,我这里用oralce,所以引用oracle.dataaccess.dll(64位或者32位,自己看情况)

2.如果是控制台项目或者winform项目相应使用spring注入的context,如我这里是

<context>
<resource uri="file://Config/BLL.xml" />
<resource uri="file://Config/Dao2.xml" />
<resource uri="file://Config/Service.xml" />
</context>

把他们改为始终复制 内容

3.用了64为的oralcle.dataaccess.dll  项目也要编译为64位的dll,把解决方案->属性->配置属性里相应项目的改为x64,配置管理器找到相应项目也改成x64,还有如我的类库是EtlTranslateInterface,那么选中它,右键属性->目标平台->x64

4.新建项目的app.config里如果有startup标签页删除掉

5.你的项目的spring和hibernate等相应的版本是匹配的可运行的,如spring.core.dll用1.0的hibernate.dll用2.0可能也不行,这里打个比方,我没看他们的版本号

1.spring环境的搭建的更多相关文章

  1. spring环境的搭建及作用和定义<一>

    问题?spring的定义及作用.spring的环境搭建 一.spring的定义及作用 1.spring由Rod Johnson创建的一个开源框架,它是为了解决企业应用开发的复杂性而创建的.框架的主要优 ...

  2. 2018.12.20 Spring环境如何搭建

    Spring学习 1.导入spring约束 为后续创建xml文件做铺垫 2.开始搭建Spring环境 1.创建Web项目,引入spring的开发包(根据下面的图来引入) 2.引入jar包 coreCo ...

  3. Spring环境的搭建与测试 (spring2.5.6)

    这里是采用的视频里面的spring版本 下载spring2.5.6, 然后进行解压缩,在解压目录中找到下面jar文件,拷贝到类路径下 dist\spring.jar lib\jakarta-commo ...

  4. SSH三个主流框架环境的搭建

    part 1  Hibernate环境的搭建 part2  struts2环境的搭建 第一步:从struts2官网下载需要的各种资料和jar包 第二步:在ecplise里面创建web项目,然后在web ...

  5. Spring环境搭建之:导入jar包、配置文件名称及放置位置

    Spring环境搭建之:导入jar包.配置文件名称及放置位置 现在项目开发中spring框架应用的还是比较多的,自己用的还不太熟练,每次用的时候总配置半天,总有些配置弄错,就找个时间总结以下,方便以后 ...

  6. 【Spring学习笔记-1】Myeclipse下Spring环境搭建

    *.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...

  7. 工作笔记3.手把手教你搭建SSH(struts2+hibernate+spring)环境

    上文中我们介绍<工作笔记2.软件开发经常使用工具> 从今天開始本文将教大家怎样进行开发?本文以搭建SSH(struts2+hibernate+spring)框架为例,共分为3步: 1)3个 ...

  8. 移动商城第三篇【搭建Mybatis和Spring环境、编写Dao、Service在Core模块】

    Mybatis和Spring环境搭建 由于我们的所编写的dao层.service代码可能前台和后台都需要用到的,因此我们把环境搭建在core模块中 逆向工程 首先,我们要做的就是品牌管理,我们首先来看 ...

  9. 【Spring环境搭建】在Myeclipse下搭建Spring环境-web开发

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...

随机推荐

  1. 柒月风华BBS上线

    论坛地址:https://3003soft.top/LBBS/ 欢迎大家加入. 开放式轻论坛:记录好玩.有趣的事儿:一起努力,一起前进: 希望能建立一个分享各类解决方案的社区

  2. uva-11205-枚举子集

    题意: 至少用多少列来表示输入中的二进制数,并且表示的数里面没有重复,最多P列,N个二进制数 所以......表示的最大二进制数是2^P,那么在2^P方内的数二进制最大值是P个1,最小是0,所以,枚举 ...

  3. Java的Synchronized

    原理,注意看输入输出,不了解原理是想不到会这样输出的. http://www.cnblogs.com/paddix/p/5367116.html 还有一个要注意的是一个对象一个monitor类

  4. Windows 域用户

    Windows 2000 组及说明 分类: Windows 2000 的组分为Security 和 Distribution 两种. Security 类型是Windows 2000 唯一用于赋予权限 ...

  5. 常用Sql语句,及注意事项

    目录: sql语句 sql命令语句 关键字 sql语句 SELECT * FROM V$reserved_words;--查询oracle预留关键字 SELECT * FROM V$version;- ...

  6. MySQLReport

    简介: MySQLReport 一.安装 shell > yum -y install mysqlreport perl-DBD-MySQL 二.使用 shell > mysqlrepor ...

  7. eclispse修改项目项目编码

    最近遇到问题,在myeclipse新建或导入项目后,有些文件中文显示乱码,每次都要在项目property中修改其编码,所以想到一次性解决所有编码问题,让项目新建或导入之后自动是utf-8编码,这样就不 ...

  8. Winform 无纸化办公-屏幕联动

    最近做无纸化办公,对接硬件,用了挺多东西总结一下 技术上主要是:asp.net .winform.activeX控件.chrome插件.socket编程,websocket. 其实看着需求挺简单的,在 ...

  9. plot绘图

    plot绘图 坐标系图(折线图) 折线图用于显示随时间或有序类别的变化趋势 plt.plot(x,y,format_string,**kwargs) y:Y轴数据,列表或数组,必选 x:X轴数据,列表 ...

  10. 最短路径-Floyd算法(转载)

            暑假,小哼准备去一些城市旅游.有些城市之间有公路,有些城市之间则没有,如下图.为了节省经费以及方便计划旅程,小哼希望在出发之前知道任意两个城市之前的最短路程.         上图中有 ...