日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

[转载]Spring配置文件详解一:

發布時間:2023/11/29 javascript 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [转载]Spring配置文件详解一: 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

原文地址:Spring配置文件詳解一:<context:annotation-config/>與<context:component-scan?base-package="com.xx 作者:愛情隨遇而安
  • <context:annotation-config/>
??? 在基于主機方式配置Spring時,Spring配置文件applicationContext.xml,你可能會見 <context:annotation-config/>這樣一條配置,它的作用是 隱式的向Spring容器注冊 ?????????????????????????? AutowiredAnnotationBeanPostProcessor, ???????????????????????????CommonAnnotationBeanPostProcessor, ?????????????????????????? PersistenceAnnotationBeanPostProcessor, ???????????????????????????RequiredAnnotationBeanPostProcessor? ?這4個BeanPostProcessor.注冊這4個bean處理器主要的作用是為了你的系統能夠識別相應的注解。????????????????????????
?例如:
  • ?如果想使用@Autowired注解,需要在Spring容器中聲明AutowiredAnnotationBeanPostProcessor Bean。傳統的聲明方式:<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
  • 如果想使用@PersistenceContext注解,需要在Spring容器中聲明PersistenceAnnotationBeanPostProcessor Bean。傳統的聲明:<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
  • 如果想使用@Required注解,需要在Spring容器中聲明RequiredAnnotationBeanPostProcessor Bean。傳統聲明方式: <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
  • 如果想使用@Resource、@ PostConstruct、@ PreDestroy等注解就必須聲明CommonAnnotationBeanPostProcessor。傳統申明方式: <bean class="org.springframework.beans.factory.annotation.CommonAnnotationBeanPostProcessor"/>
  • 所以,如果按照傳統聲明一條一條去聲明注解Bean,就會顯得十分繁瑣。
    因此如果在Spring的配置文件中事先加上
    <context:annotation-config/>這樣一條配置的話,那么所有注解的傳統聲明就可以被? 忽略,即不用在寫傳統的聲明,Spring會自動完成聲明。

    • <context:component-scan base-package="com.xx" />?

    ? ? <context:component-scan/> 的作用是讓Bean定義注解工作起來,也就是上述傳統聲明方式。 它的base-package屬性指定了需要掃描的類包,類包及其遞歸子包中所有的類都會被處理。

    ???? 值得注意的是 <context:component-scan/>不但啟用了對類包進行掃描以實施注釋驅動 Bean 定義的功能,同時還啟用了注釋驅動自動注入的功能(即還隱式地在內部注冊了 AutowiredAnnotationBeanPostProcessor 和? CommonAnnotationBeanPostProcessor),因此當使用 <context:component-scan/> 后,就可以將 <context:annotation-config/> 移除了。 ? @Autowired可以對成員變量、方法和構造函數進行標注,來完成自動裝配的工作。@Autowired的標注位置不同,它們都會在Spring在初始化這個bean時,自動裝配這個屬性。注解之后就不需要set/get方法了。

    轉載于:https://my.oschina.net/haokevin/blog/1555815

    總結

    以上是生活随笔為你收集整理的[转载]Spring配置文件详解一:的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。