zoukankan      html  css  js  c++  java
  • Spring、Hello Spring

    1、引入Spring jar包

    2、新建一个Person 接口和Person Bean

    public interface PersonIService {
    	public void helloSpring();
    }

    import cn.server.PersonIService;
    
    public class PersonServiceImpl implements PersonIService {
    
    	@Override
    	public void helloSpring() {
    		System.out.println("Hello Spring!");
    	}
    }
    

    3、将PersonBean在beans.xml中注入:

    <bean id="personIService" class="cn.server.impl.PersonServiceImpl" />

    4、使用ClassPathXmlApplicationContext 解析beans.xml  并得到PersonBean对象

    @Test
    	public void test() {
    		ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
    		PersonIService personIService=(PersonIService)ac.getBean("personIService");
    		personIService.helloSpring();
    	}



  • 相关阅读:
    组合模式
    过滤器模式
    桥接模式
    适配器模式
    原型模式
    建造者模式
    抽象工厂
    工厂方法
    静态工厂
    单例模式
  • 原文地址:https://www.cnblogs.com/raphael5200/p/5114746.html
Copyright © 2011-2022 走看看