欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

spring @component的作用詳細(xì)介紹

 更新時間:2017年04月24日 15:00:44   投稿:lqh  
這篇文章主要介紹了spring @component的作用詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下

spring @component的作用詳細(xì)介紹

1、@controller 控制器(注入服務(wù))
2、@service 服務(wù)(注入dao)
3、@repository dao(實(shí)現(xiàn)dao訪問)
4、@component (把普通pojo實(shí)例化到spring容器中,相當(dāng)于配置文件中的<bean id="" class=""/>)

  @Component,@Service,@Controller,@Repository注解的類,并把這些類納入進(jìn)spring容器中管理。

下面寫這個是引入component的掃描組件

<context:component-scan base-package=”com.mmnc”> 

 其中base-package為需要掃描的包(含所有子包) 

       1、@Service用于標(biāo)注業(yè)務(wù)層組件
       2、@Controller用于標(biāo)注控制層組件(如struts中的action)
       3、@Repository用于標(biāo)注數(shù)據(jù)訪問組件,即DAO組件.
       4、@Component泛指組件,當(dāng)組件不好歸類的時候,我們可以使用這個注解進(jìn)行標(biāo)注。   
             @Service public class UserServiceImpl implements UserService { }      

            @Repository public class UserDaoImpl implements UserDao { } getBean的默認(rèn)名稱是類名(頭字母小寫),如果想自定義,可以@Service(“***”)               這樣來指定,這種bean默認(rèn)是單例的,如果想改變,可以使用@Service(“beanName”) 

           @Scope(“prototype”)來改變??梢允褂靡韵路绞街付ǔ跏蓟椒ê弯N毀方法(方法名任意): @PostConstruct public void init() { }

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論