天天看點

java中注解[email protected]注解的解析

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

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

其中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() { }