zoukankan      html  css  js  c++  java
  • spring实现helloWord

    第一步:添加架包

    第二步:写一个简单的实列

    package com.java.test;
    
    /**
     * @author nidegui
     * @create 2019-06-22 10:58
     */
    public class Helloworld {
    
        public void say(){
            System.out.println("nihao spring");
        }
    }
    

      

    第三步:用bean

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    	<bean id="helloWorld" class="com.java.test.Helloworld"></bean>
    
      
    </beans>
    

      

    第四步:测试

    package com.java.test;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    /**
     * @author nidegui
     * @create 2019-06-22 11:00
     */
    public class Test {
        public static void main(String[] args) {
            ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml"); //获取bean
            Helloworld helloWorld = (Helloworld) ac.getBean("helloWorld");   //获取bean的名字
            helloWorld.say();
        }
    }
    

      

  • 相关阅读:
    String类的操作方法
    操作日期时间类 Calendar类
    JAVA中Date类的使用
    集合方法整理
    JAVA日期——java.util.date类的操作
    关于Collections的操作方法
    java中集合
    java中继承的关系
    java
    封装继承多态-java面向对象三大特征
  • 原文地址:https://www.cnblogs.com/nidegui/p/11068161.html
Copyright © 2011-2022 走看看