天天看點

spring注解: @componet 、@Repository、@Service 和 @Controller

1、@Service用于标注業務層元件

如: @Service (value= "aclService"   ) @Transactional public   class   AclServiceImpl   implements   AclService { }

2、@Controller用于标注控制層元件(如struts中的action)

  3、@Repository用于标注資料通路元件,即DAO元件 如: @Repository public   class   AclDaoImpl   extends   HibernateBaseDao<Acl, Integer>   implements   AclDao{ }   4、 @Component泛指元件,當元件不好歸類的時候,我們可以使用這個注解進行标注

5、注入式(注解)@Autowired    @Service (value= "aclService"   ) @Transactional public   class   AclServiceImpl   implements   AclService {          private   static   final   Logger   logger =Logger.getLogger(AclServiceImpl.   class );                   @Autowired          private   AclDao   dao   =   null ;

}

6、事務 @Transactional