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

歡迎訪問 生活随笔!

生活随笔

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

javascript

Spring过滤器组件自动扫描

發布時間:2024/9/20 javascript 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring过滤器组件自动扫描 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在這個Spring自動組件掃描的教程,您已經了解如何使Spring自動掃描您的組件。在這篇文章中,我們將展示如何使用組件過濾器自動掃描過程。 1.過濾組件?- 包含 參見下面的例子中使用Spring?“過濾”?掃描并注冊匹配定義“regex”,即使該類組件的名稱未標注?@Component?。

DAO 層

package com.yiibai.customer.dao;public class CustomerDAO {@Overridepublic String toString() {return "Hello , This is CustomerDAO";} }

Service 層

package com.yiibai.customer.services;import org.springframework.beans.factory.annotation.Autowired; import com.yiibai.customer.dao.CustomerDAO;public class CustomerService {@AutowiredCustomerDAO customerDAO;@Overridepublic String toString() {return "CustomerService [customerDAO=" + customerDAO + "]";}}

Spring 過濾

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd"><context:component-scan base-package="com.yiibai" ><context:include-filter type="regex" expression="com.yiibai.customer.dao.*DAO.*" /><context:include-filter type="regex" expression="com.yiibai.customer.services.*Service.*" /></context:component-scan></beans>

執行

package com.yiibai.common;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import com.yiibai.customer.services.CustomerService;public class App {public static void main( String[] args ){ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"Spring-AutoScan.xml"});CustomerService cust = (CustomerService)context.getBean("customerService");System.out.println(cust);} }

輸出

CustomerService [customerDAO=Hello , This is CustomerDAO] 在這個XML過濾中,所有文件的名稱中包含 DAO 或?Service(*DAO.*,?*Services.*) 單詞將被檢測并在 Spring 容器中注冊。 2.過濾組件?-?不包含 另外,您還可以排除指定組件,以避免?Spring?檢測和?Spring?容器注冊。不包括在這些文件中標注有?@Service?。 <context:component-scan base-package="com.yiibai.customer" ><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> </context:component-scan> 不包括那些包含DAO這個詞組文件名。 <context:component-scan base-package="com.yiibai" ><context:exclude-filter type="regex" expression="com.yiibai.customer.dao.*DAO.*" /> </context:component-scan> 下載代碼 –?http://pan.baidu.com/s/1pKnzB2F

總結

以上是生活随笔為你收集整理的Spring过滤器组件自动扫描的全部內容,希望文章能夠幫你解決所遇到的問題。

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