首页 > 编程语言 > 详细

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

时间:2019-09-20 16:06:53      阅读:88      评论:0      收藏:0      [点我收藏+]

记录一下自己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>

 

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

原文:https://www.cnblogs.com/zhang188660586/p/11557037.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!