1、创建bean
/*
*@Author swxctx
*@time 2016年9月27日
*/
package com.sw.service;
import org.springframework.stereotype.Controller;
@Controller(value="personServiceBean")
public class personServiceBean {
public void save(){
System.out.println("PersonServiceBean");
}
}
/*
*@Author swxctx
*@time 2016年9月27日
*/
package com.sw.service1;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import com.sw.service.personServiceBean;
@Controller(value="userServiceBean")
public class userServiceBean {
@Resource
public personServiceBean psb=null;
public static personServiceBean createPerson(){
return new personServiceBean();
}
@PostConstruct
public void add(){
psb.save();
}
}
3、配置文件
<?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">
<context:component-scan base-package="com.sw.service"></context:component-scan>
<context:component-scan base-package="com.sw.service1"></context:component-scan>
</beans>