zoukankan      html  css  js  c++  java
  • @component的注解

    1、@controller 控制器(注入服务)
    2、@service 服务(注入dao)
    3、@repository dao(实现dao访问)
    4、@component (把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class=""/>)
    @Component:
     定义Spring管理Bean
    
    
    

    @Repository:

    @Component扩展,被@Repository注解的POJO类表示DAO层实现,从而见到该注解就想到DAO层实现,使用方式和@Component相同;

    @Service:

    @Component扩展,被@Service注解的POJO类表示Service层实现,从而见到该注解就想到Service层实现,使用方式和@Component相同;

    @Controller:

    @Component扩展,被@Controller注解的类表示Web层实现,从而见到该注解就想到Web层实现,使用方式和@Component相同;

      @Component,@Service,@Controller,@Repository注解的类,并把这些类纳入进spring容器中管理。 
    下面写这个是引入component的扫描组件 
    <context:component-scan base-package=”com.mmnc”>    

    其中base-package为需要扫描的包(含所有子包) 
           1、@Service用于标注业务层组件 
           2、@Controller用于标注控制层组件(如struts中的action) 
           3、@Repository用于标注数据访问组件,即DAO组件. 
           4、@Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。    
               @Service 
               public class UserServiceImpl implements UserService { } 
               @Repository 
               public class UserDaoImpl implements UserDao { } getBean的默认名称是类名(头字母小写),如果想自定义,可以@Service(“***”)                          这样来指定,这种bean默认是单例的,如果想改变,可以使用@Service(“beanName”) 
               @Scope(“prototype”)来改变。可以使用以下方式指定初始化方法和销毁方法(方法名任意): @PostConstruct public void init() { } 
    
    
              详细:http://blog.csdn.net/zhang854429783/article/details/6785574

    引用原文:https://blog.csdn.net/thinkingcao/article/details/71171222

    写博客是为了记住自己容易忘记的东西,另外也是对自己工作的总结,文章可以转载,无需版权。希望尽自己的努力,做到更好,大家一起努力进步!

    如果有什么问题,欢迎大家一起探讨,代码如有问题,欢迎各位大神指正!

  • 相关阅读:
    poj 3125 Printer Queue(STL注意事项)
    poj 2823 Sliding Window (STL超时版)
    poj 1088 滑雪 详解
    poj 2983 Is the Information Reliable?
    poj 2524 Ubiquitous Religions (STL与非STL的对比)
    高精度算法集合
    zTree v2.6 v3.0 初始化 / 方法对比
    下面是关于rownum的介绍(oracle)
    web性能优化
    jQueryEasyui,DataGrid几个常用的操作
  • 原文地址:https://www.cnblogs.com/summary-2017/p/8974152.html
Copyright © 2011-2022 走看看