1.@Resource注解:
2.注解2
例子:
1、dao层:
package com.wuyonghu.jsr;
import org.springframework.stereotype.Repository;
@Repository
public class JsrDAO {
public void save(){
System.out.println("JsrDAO中的save方法執行了");
}
}
service层:
package com.wuyonghu.jsr;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class JsrService {
//这里无论是使用@Resource注解到属性上,或者是setter方法上,都是可以的,作用和@Autowired注解相似
// @Resource
private JsrDAO jsrDAO;
@Resource
public void setJsrDAO(JsrDAO jsrDAO) {
this.jsrDAO = jsrDAO;
}
public void save() {
System.out.println("jsrService中的方法");
jsrDAO.save();
}
}