接口Service:

package com.spring.service;

public interface DogPetService {
public void queryAllDogPets();
}

实现类ServiceImpl:

package com.spring.service.impl;

import java.util.List;

import javax.annotation.Resource;

import com.spring.service.DogPetService;
import com.spring.dao.DogPetDAO;
import com.spring.model.DogPet; public class DogPetServiceImpl implements DogPetService{ private DogPetDAO dogPetDAO; public DogPetDAO getDogPetDAO() {
return dogPetDAO;
} @Resource(name="dogPetDAO1")
public void setDogPetDAO(DogPetDAO dogPetDAO) {
this.dogPetDAO = dogPetDAO;
} @Override
public void queryAllDogPets() {
List<DogPet> list = dogPetDAO.queryAllDogPets();
if(list != null)
{
for(DogPet d:list)
{
System.out.println(d.toString());
}
}
} }

Service的调用DAO类:

package com.spring.dao;

import java.util.ArrayList;
import java.util.List; import com.spring.model.DogPet; public class DogPetDAO { public List<DogPet> queryAllDogPets()
{
List<DogPet> list = new ArrayList<DogPet>(); DogPet d1 = new DogPet();
d1.setId(1111);
d1.setName("dog1");
d1.setAge(4);
d1.setKind("buladuo");
d1.setSex("B");
d1.setHealth("good");
DogPet d2 = new DogPet();
d2.setId(2222);
d2.setName("dog2");
d2.setAge(3);
d2.setKind("buladuo");
d2.setSex("G");
d2.setHealth("good"); list.add(d1);
list.add(d2); return list;
}
}

配置文件:

<?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" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/> <bean id="dogPetService" class="com.spring.service.impl.DogPetServiceImpl"> </bean> <bean id="dogPetDAO1" class="com.spring.dao.DogPetDAO"> </bean>
</beans>

test类:

package com.spring.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.spring.service.DogPetService; public class ResourceTest { @Test
public void queryAllDogPets()
{
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
DogPetService dogPetService = (DogPetService)ctx.getBean("dogPetService");
dogPetService.queryAllDogPets();
} }

spring_150802_resource的更多相关文章

随机推荐

  1. 使用Git和远程代码库

    git是个了不起但却复杂的源代码管理系统.它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作.让我们诚实一记吧:Git是复杂的,我们不要装作它不是.但我仍然会试图教会你用(我的)基本 ...

  2. linux系统下sd卡的备份与恢复

    linux系统下sd卡的备份与恢复 现在各种的开发板都是从sd卡上面启动的,因此大修改工作之前很有必要备份一下. 备份 在linux系统下用读卡器读取sd卡 用df -h命令看分区的路径 一般都是/d ...

  3. licens 问题 Error (292028): Specified license is not valid for this machine

    集成网卡调试的时候坏了,造成了quartus 不可以用,MAC地址不对应了... 应该怎么解决呢??.

  4. 一个关于C#中基类与接口混合继承的疑问总结

    思路参照 http://www.cnblogs.com/allenlooplee/archive/2004/11/16/64553.html,对原文进行了简化和补充,感谢原作者. 问题很简单,如下所示 ...

  5. Daily Scrum7

    今天我们小组开会内容分为以下部分: part 1: 研讨上一届的项目里积分制度的功能,确定其不足,以及我们可以改进的地方: part 2: 讨论确定我们项目的积分制度的功能目标: part 3:针对用 ...

  6. hadoop日志太大

    hadoop jobtracker日志太大在jobtracker服务器上的mapred-site.xml中添加以下参数: <property> <name>mapreduce. ...

  7. IOC框架的认识

    转:http://blog.csdn.net/wanghao72214/article/details/3969594 1 IoC理论的背景 我们都知道,在采用面向对象方法设计的软件系统中,它的底层实 ...

  8. MD5加密(C#)

    先来说说Md5 MD5为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护. md5有很多广泛的功能.大家都知道,数据库里面密码不会直接存该密码,而是加密之后的字符串.这时候你就可以把密码 ...

  9. 计算器软件的代码实现 (策略模式+asp.net)

    一 策略模式代码的编写 using System; using System.Collections.Generic; using System.Linq; using System.Web; /// ...

  10. 【BZOJ】【1202】【HNOI2005】狡猾的商人

    Orz iwtwiioi  http://www.cnblogs.com/iwtwiioi/p/3887617.html 并查集+前缀和 啊……这题应该是水题吧?但是我这个大沙茶居然一天都没想出来…… ...