Spring阶段性学习总结(一)实现一个简单的HellowWorld

记录一下自己Spring的学习历程

 1 package HelloWorld;
 2 
 3 public class HelloWorld {
 4 
 5     String name;
 6 
 7     public void setName(String name) {
 8         this.name = name;
 9     }
10 
11     public void hello() {
12         System.out.println("helloWorld:" + name);
13     }
14 
15     public HelloWorld() {
16         System.out.println("我是构造方法!");
17     }
18 }

 

 1 package HelloWorld;
 2 
 3 import org.springframework.context.support.ClassPathXmlApplicationContext;
 4 
 5 public class Main {
 6     public static void main(String[] args) {
 7        
 8         ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("HelloWorld/applicationContext.xml");
 9         HelloWorld helloWorld = (HelloWorld) applicationContext.getBean("helloWorld");
10         helloWorld.hello();
11 
12     }
13 }

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 6 
 7     <bean id="helloWorld" class="HelloWorld.HelloWrold">
 8         <property name="name" value="张浩"></property>
 9     </bean>
10 
11 </beans>

 

posted @ 2019-09-20 14:41  我叫张小凡  阅读(170)  评论(0编辑  收藏  举报