當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring组件扫描context:component-scan/使用详解
生活随笔
收集整理的這篇文章主要介紹了
Spring组件扫描context:component-scan/使用详解
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.如果不想在xml文件中配置bean,我們可以給我們的類加上spring組件注解,只需再配置下spring的掃描器就可以實現(xiàn)bean的自動載入。
<!-- 注解注入 --> <context:annotation-config></context:annotation-config> <context:component-scan base-package="com.liantuo.hotel.common.service.impl" /> <context:component-scan base-package="com.liantuo.hotel.common.dao.ibatis" /> <context:component-scan base-package="com.liantuo.hotel.app.dao.ibatis" /> <context:component-scan base-package="com.liantuo.hotel.app.service" /> <context:component-scan base-package="com.liantuo.hotel.app.service.ibatis" /> “ @Component(組件)@Service(服務(wù)層)@Controller(控制層)@Repository(數(shù)據(jù)庫訪問層) 3.有了<context:component-scan>,另一個<context:annotation-config/>標(biāo)簽根本可以移除掉,因為已經(jīng)被包含進去了。 <context:component-scan>提供兩個子標(biāo)簽:<context:include-filter>和<context:exclude-filter>各代表引入和排除的過濾。 <context:component-scan base-package="com.xhlx.finance.budget" ><context:include-filter type="regex" expression=".service.*"/>
</context:component-scan>
Filter Type
| Examples Expression | Description | |
| annotation | org.example.SomeAnnotation | 符合SomeAnnoation的target class |
| assignable | org.example.SomeClass | 指定class或interface的全名 |
| aspectj | org.example..*Service+ | AspectJ語法 |
| regex | org\.example\.Default.* | Regelar Expression |
| custom | org.example.MyTypeFilter | Spring3新增自訂Type,實作org.springframework.core.type.TypeFilter |
總結(jié)
以上是生活随笔為你收集整理的Spring组件扫描context:component-scan/使用详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BeanPostProcessor使用心
- 下一篇: 如何识别桂圆干?