zoukankan      html  css  js  c++  java
  • Spring引用测试

    上下文

    using System;
    using Spring.Core;
    using Spring.Aop;
    using System;
    using Spring.Core;
    using Spring.Aop;
    using Spring.Context;
    using Spring.Context.Support;
    
    namespace SpringTest
    {
        /// <summary>
        /// SpringFactory 的摘要说明。
        /// </summary>
        public class SpringContext
        {
            public SpringContext()
            {
                //
                // TODO: 在此处添加构造函数逻辑
                //
            }
            private static bool isInit = false;
            private static IApplicationContext context;
            public static void init()
            {
                string[] xmlFiles = new string[1];
                xmlFiles[0] = "assembly://Spring/SpringTest/Spring_bean.xml";
                //context = new XmlApplicationContext(new string[1] { "assembly://SpringTest/SpringTest/Spring_bean.xml" });
                context = new XmlApplicationContext(xmlFiles);
                isInit = true;
            }
    
            public static IApplicationContext Context
            {
                get
                {
                    if (!isInit)
                    {
                        init();
                    }
                    return context;
                }
            }
        }
    }
    View Code

    方法类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace SpringTest.Main
    {
        public class SpringMain
        {
            public SpringMain()
            {
    
            }
    
            public void Test()
            {
                Console.WriteLine("Spring.NET测试");
            }
        }
    }
    View Code

    方法调用测试

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace SpringTest.Main
    {
        public class SpringTest
        {
            public SpringTest()
            {
    
            }
            [STAThread]
            public static void MainFun() 
            {
                //Startup Spring Content
                SpringContext.init();
    
                //Test Spring IOC
                SpringMain test = (SpringMain)SpringContext.Context.GetObject("SpringTestConfigPoint");
                test.Test();
            }
        }
    }
    View Code

    配置文件(嵌入的资源)

    <?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="SpringTestConfigPoint" type="SpringTest.Main.SpringMain,Spring" />
    </objects>
    View Code
  • 相关阅读:
    lombok 下的@Builder注解用法
    (springboot)自定义Starter
    各种 Spring-Boot-Starters系列 介绍
    MQ的使用场景
    SpringBoot中使用rabbitmq,activemq消息队列和rest服务的调用
    RPC原理详解
    Java性能优化的50个细节
    thinkphp3.2.2有预览的多图上传
    关于php中的exec命令
    关于thinkphp3.1无法加载模块解决办法
  • 原文地址:https://www.cnblogs.com/FlowingSun/p/3409672.html
Copyright © 2011-2022 走看看