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>

 

转载于:https://www.cnblogs.com/zhang188660586/p/11557037.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值