본문 바로가기
Back-end/Spring Framework

java spring , controller & dao & service 객체

by javapp 자바앱 2020. 8. 8.
728x90

1. controller

 

@Controller
public class MemberController {

//     MemberService service = new MemberService(); //지양

//     @Autowired //자동주입

       @Resource(name="memService")

       MemberService service;

      

 

 

2. dao

//@Component
@Repository //자동 주입 가능
public class MemberDao implements IMemberDao {

 

 

 

3. service

컨테이너 설정 안해도 주입 가능

//@Service     //(추천)서비스로 컨테이너에 담겨라
//@Service("memService")
//@Component
//@Component("memService")
//@Repository
@Repository("memService")
public class MemberService implements IMemberService {

  @Autowired
  MemberDao dao;

댓글