微科社区,轻松开发从此开始! 请登陆 免费注册

微科社区

当前位置:首页 > Java平台 > J2EE >

spring开发_使用p名称空间配置属性

时间:2017-01-17 03:30  浏览:努力统计中...
项目结构: http://www.cnblogs.com/hongten/gallery/image/112563.html /spring_1400_p名称空间/src/com/b510/app/test/SpringTest.java 1 package com.b510.app.test; 2 3 import org.springframework.context.ApplicationContext; 4 import org.s

项目结构:

http://www.cnblogs.com/hongten/gallery/image/112563.html

/spring_1400_p名称空间/src/com/b510/app/test/SpringTest.java

 1 package com.b510.app.test;
2
3 import org.springframework.context.ApplicationContext;
4 import org.springframework.context.support.ClassPathXmlApplicationContext;
5
6 import com.b510.service.AnimalService;
7
8 public class SpringTest {
9 public static void main(String[] args) {
10 ApplicationContext act = new ClassPathXmlApplicationContext("beans.xml");
11 // 获取id为animaleServiceOfDog的Bean
12 AnimalService animalServiceOfDog = (AnimalService) act
13 .getBean("animaleServiceOfDog");
14 animalServiceOfDog.getInfo();
15 // 获取id为animaleServiceOfCat的Bean
16 AnimalService animalServiceOfCat = (AnimalService) act
17 .getBean("animaleServiceOfCat");
18 animalServiceOfCat.getInfo();
19 }
20 }

/spring_1400_p名称空间/src/com/b510/service/AnimalService.java

 1 package com.b510.service;
2
3 /**
4 * 动物抽象类
5 *
6 * @author Hongten
7 *
8 */
9 public interface AnimalService {
10
11 /**
12 * 获取相关信息
13 */
14 public abstract void getInfo();
15
16 }

/spring_1400_p名称空间/src/com/b510/service/MeatService.java

 1 package com.b510.service;
2
3 /**
4 * 定义抽象类MeatService肉类
5 *
6 * @author Hongten
7 *
8 */
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线------
栏目列表
推荐内容