博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring入门(一) 根据xml实例化一个对象
阅读量:4508 次
发布时间:2019-06-08

本文共 1876 字,大约阅读时间需要 6 分钟。

文档: 

包下载的位置 

1.pom如下:

1 
2
3
org.springframework
4
spring-core
5
5.0.9.RELEASE
6
7
8
org.springframework
9
spring-context
10
5.0.9.RELEASE
11
12
13
14
org.springframework
15
spring-beans
16
5.0.9.RELEASE
17
18
19
20
org.springframework
21
spring-expression
22
5.0.9.RELEASE
23
View Code

2.建立User类

1 public class User { 2     private String name; 3     private Integer age; 4  5     public String getName() { 6         return name; 7     } 8  9     public void setName(String name) {10         this.name = name;11     }12 13     public Integer getAge() {14         return age;15     }16 17     public void setAge(Integer age) {18         this.age = age;19     }20 }
View Code

3.xml配置

1 
2
6 7
8
9
10 11
12
13
14 15
16 17

4.实例化User类

main方法里:

import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
1         //位置:setting/applicationContext.xml2         ApplicationContext context = new ClassPathXmlApplicationContext("setting/applicationContext.xml");3         User user = context.getBean("user",User.class);4         System.out.println(user);

 

转载于:https://www.cnblogs.com/ICE_Inspire/p/9721382.html

你可能感兴趣的文章
robotframework-selenium2library各个版本
查看>>
插入排序
查看>>
LeetCode全文解锁 √
查看>>
[BZOJ 1566] 管道取珠
查看>>
[Codeforces 1060F] Shrinking Tree
查看>>
Winfrom 桌面弹窗拦截 关闭进程简易程序 源代码下载
查看>>
NGUI Atlas Panel和Depth的关系
查看>>
推荐一些相见恨晚的 Python 库 「一」
查看>>
POJ 1062 昂贵的聘礼 (带限制的最短路)
查看>>
TCP协议、UDP协议、端口、套接字
查看>>
设计模式之——单例模式
查看>>
Linux下vim上编辑实现进度条
查看>>
ubuntu 设置plank开机自启之后关机键失效变为注销键
查看>>
JS--我发现,原来你是这样的JS(三)(基础概念--灵魂篇)
查看>>
手指滑动切换手机图片
查看>>
解决Oracle EM无法启动
查看>>
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
查看>>
PHP 跨域资源共享 CORS 设定
查看>>
男神鹏:使用Redis 的一些 问题解决方案。
查看>>
创建空间参考
查看>>