zoukankan      html  css  js  c++  java
  • spring简单示例

    1 配置config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
        <!-- 定义一个bean id表示唯一一个bean class表示bean的来源 -->
        <bean id="HelloWorld" class="com.gc.action.HelloWorld">
            <!-- 将其变量msg通过依赖注入 -->
            <property name="msg">
                <value>HelloWorld</value>
            </property>
        </bean>
    </beans>
    View Code

    2 实体类

    package com.gc.action;
    
    public class HelloWorld {
        public String msg = null;
    
        public String getMsg() {
            return msg;
        }
    
        public void setMsg(String msg) {
            this.msg = msg;
        }
    
    }
    View Code



    3 编写测试示例

    package com.gc.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.FileSystemXmlApplicationContext;
    
    import com.gc.action.HelloWorld;
    public class TestHelloWorld {
        public static void main(String[] args) {
            @SuppressWarnings("resource")
            ApplicationContext actx = new FileSystemXmlApplicationContext("config.xml");
            HelloWorld hello=(HelloWorld)actx.getBean("HelloWorld");
            System.out.println(hello.getMsg());
        }
    }
    View Code
  • 相关阅读:
    JAVA 异常
    JAVA 接口的基本语法
    JAVA 访问权限
    Linux shell 函数应用示例02
    Linux shell 函数应用示例01
    Linux shell while循环语句
    Linux shell 中断循环语句
    Linux shell for循环结构
    测试用例基本概念
    软件测试原则
  • 原文地址:https://www.cnblogs.com/studyjava/p/5194734.html
Copyright © 2011-2022 走看看