,泛指各種元件。"/> ,泛指各種元件。">

首頁  >  文章  >  component什麼層註解

component什麼層註解

anonymity
anonymity原創
2019-05-08 14:03:013977瀏覽

@component(把普通pojo實例化到spring容器中,相當於設定檔中的bd9834840cb7d421013feffd38ea2293)

泛指各種元件,就是說當我們的類別不屬於各種歸類的時候(不屬於@Controller、@Services等的時候),我們就可以使用@Component來標註這個類別。

component什麼層註解

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

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

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

       1、@Service用於標註業務層元件 
       2、@Controller使用標註控制層元件(如struts中的action) 
       3、@Repository
       4、@Component泛指元件,當元件不好歸類的時候,我們可以使用這個註解來標註。
             @Service public class UserServiceImpl implements UserService { }      

      頭字母小寫),如果想自訂,可以@Service(“ ***”)               以如此指定,以這種bean預設為單例的,若想改變,可使用@Service(「beanName」) 

    可以使用以下方式指定初始化方法和銷毀方法(方法名稱任意): @PostConstruct public void init() { }

以上是component什麼層註解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn