package com.bebig.service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.bebig.dao.UserDAO;
import com.bebig.model.User;

//相当于在XML中配置了scope
@Scope("singleton")
@Service(
"userService")
public class UserService {
    
private UserDAO userDAO;

    
public void add(User u) {
        userDAO.save(u);

    }


    @Resource(name 
= "u")
    
public void setUserDAO(UserDAO userDAO) {
        
this.userDAO = userDAO;
    }


    
public UserDAO getUserDAO() {
        
return userDAO;
    }


    
// 相当于在XML中配置了init-method
    @PostConstruct
    
public void init() {
        System.out.println(
"init.");
    }


    
// 相当于在XML中配置了destroy-method
    @PreDestroy
    
public void destory() {
        System.out.println(
"destory.");
    }

}

 

  @PostConstruct = init-method; @PreDestroy = destroy-method;