spring 框架搭建并创建第一个小程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014535666/article/details/51580981

首先是类的创建

public class Student {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}


}



主函数


public class mian {


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext app=new ClassPathXmlApplicationContext("applicationContext.xml");
Student st=(Student) app.getBean("st");
System.out.println(st.getName());
}


}

spring 配置文件  applicationContext.xml




<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="st" class="cn.zs.com.Student">


<property name="name" value="zhangsan"></property>
<property name="age" value="12"></property>




</bean>


</beans>




猜你喜欢

转载自blog.csdn.net/u014535666/article/details/51580981
今日推荐