Spring04---Annotation注入

来源:互联网 发布:正版mac ps软件多少钱 编辑:程序博客网 时间:2024/05/15 23:50

Annotation注入

这里写图片描述

1.1 创建Bean 使用@Component

这里写图片描述

1.2 做依赖注入, 在setter方法上添加@Resource

这里写图片描述

1.2.1 测试添加

这里写图片描述

1.3、设置多例prototype

这里写图片描述

2、为了更好区分分层, bean的注解,不在使用@component

@Repository("userDao")  //@Repository一般使用Dao的注入public class UserDao implements IUserDao{@Service("userService")   //业务层一般使用@Servicepublic class UserService implements IUserService {@Controller("userAction")  //MVC控制层一般使用@Controller@Scope("prototype")public class UserAction {
原创粉丝点击