第一步:添加架包

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

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 ></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();
    }
}

  spring实现helloWord

 

相关文章:

  • 2021-10-06
  • 2021-12-24
  • 2021-09-27
  • 2022-01-31
  • 2021-04-29
  • 2021-09-09
  • 2021-12-03
猜你喜欢
  • 2021-09-27
  • 2022-12-23
  • 2021-11-10
  • 2021-05-20
相关资源
相似解决方案