<?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:context="http://www.springframework.org/schema/context"
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">
<!--
spring类扫描
在 base-package 的包以及子包进行类扫描(但是类要标上component 注解)
-->
<context:component-scan base-package="com.xiaoke"></context:component-scan>
</beans>
PersonDao.java
package com.xiaoke.Dao;
import com.xiaoke.model.Person;
public interface PersonDao {
/**
* 保存人员
*/
public void savaPerson(Person person);
}
PersonService.java
package com.xiaoke.Service;
import com.xiaoke.model.Person;
public interface PersonService {
/**
* 保存人员
*/
public void savaPerson(Person person);
}
PersonServiceImpl.java
package com.xiaoke.Service.Impl;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.xiaoke.Dao.PersonDao;
import com.xiaoke.Service.PersonService;
import com.xiaoke.model.Person;
//@Component("personService") //这个是通用的,功能跟@Service() @Controller("personAction") 是一样的
@Service("personService")
public class PersonServiceImpl implements PersonService {
@Resource
private PersonDao personDao;
/**
* 保存人员
*/
public void savaPerson(Person person){
personDao.savaPerson(person);
}
}
PersonAction.java
package com.xiaoke.Action;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.xiaoke.Service.PersonService;
import com.xiaoke.model.Person;
//@Component("personAction") //这个是通用的,功能跟@Service() @Controller("personAction") 是一样的
@Controller("personAction")
@Scope("prototype") //改为多例
public class PersonAction {
@Resource
private PersonService personService;
/**
* 保存人员
*/
public void savaPerson(Person person){
personService.savaPerson(person);
}
}