前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
1、@controller 控制器(注入服務)
2、@service 服務(注入dao)
3、@repository dao(實現dao訪問)
4、@component (把普通pojo實例化到spring容器中,相當于配置文件中的<bean id="" class=""/>)? @Component,@Service,@Controller,@Repository注解的類,并把這些類納入進spring容器中管理。?
下面寫這個是引入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() { }?
轉自:http://tomfish88.iteye.com/blog/1497557
?