zoukankan      html  css  js  c++  java
  • spring hello world 入门

    参考:http://c.biancheng.net/view/4244.html

    1.下载包

    2.新建接口+类

    3.新建xml文件

    4.测试

    package com.ligy.ioc;
    
    public interface IStudent {
        void do1();
    }
    package com.ligy.ioc;
    
    public class StudentImpl implements IStudent {
        @Override
        public void do1() {
            System.out.println("this is in do1");
        }
    }
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
        <!-- 由 Spring容器创建该类的实例对象 -->
        <bean id="studentDao" class="com.ligy.ioc.StudentImpl" />
    </beans>
    package com.ligy.test;
    
    import com.ligy.ioc.StudentImpl;
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    
    public class Test1 {
    
        @Test
        public void do1() {
            // 定义Spring配置文件的路径
            String xmlPath = "applicationContext.xml";
            // 初始化Spring容器,加载配置文件
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                    xmlPath);
            // 通过容器获取personDao实例
            StudentImpl personDao = (StudentImpl) applicationContext
                    .getBean("studentDao");
            // 调用 personDao 的 add ()方法
            personDao.do1();
        }
    }

     

    天生我材必有用,千金散尽还复来
  • 相关阅读:
    SharePoint中获取当前登录的用户名
    SharePoint 2013 图文开发系列之InfoPath入门
    在InfoPath中如何获取当前用户的信息(Profile)
    更新当前列并添加其他列
    poj3067 Japan
    poj2481 Cows
    poj1195 Mobile phones
    poj2299 Ultra-QuickSort
    lower_bound()和upper_bound
    hdu4339 Query
  • 原文地址:https://www.cnblogs.com/ligenyun/p/14743453.html
Copyright © 2011-2022 走看看