英文建站多少钱,网页素材网站免费,wordpress上传大图,找人建设网站1、导包#xff08;此处省略如何下载Spring文件#xff09; 打开我们的spring-framework-4.2.3.RELEASE文件#xff08;这里我们只导入最基础的几个包#xff09;#xff0c;再打开libs文件#xff1a; 找到以下几个包#xff1a; 复制粘贴到eclipse中去#xff0c;如…1、导包此处省略如何下载Spring文件 打开我们的spring-framework-4.2.3.RELEASE文件这里我们只导入最基础的几个包再打开libs文件 找到以下几个包 复制粘贴到eclipse中去如果有以下两个包最好也一起复制粘贴logging是日志包另一个是保证低版本spring也可以用 2、创建一个对象
public class User {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;}}3、书写配置注册对象到容器位置任意建议放在src下配置文件名任意建议applicationContext.xml,接着导入约束按着图片做就可以了 在配置好以上文件时打开applicationContext.xml文件在里面配置如下代码
?xml version1.0 encodingUTF-8?
beans xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlnshttp://www.springframework.org/schema/beans xsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd bean nameuser classcn.it.bean.User/bean
/beans4、以上就配置好了代码测试
public class test1 {Testpublic void test() {//1、获取容器对象ApplicationContext ac new ClassPathXmlApplicationContext(applicationContext.xml);//2、获取对象User user (User) ac.getBean(user);//3、输出对象System.out.println(user);}
}
结果