Spring-IoC-DI-基於註解方式的依賴注入(元件掃描配置)
阿新 • • 發佈:2020-08-16
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 開始元件掃面 --> <!-- 1.如果掃描多個包,多個包使用逗號隔開2.掃描包上層目錄 --> <context:component-scan base-package="com.orzjiangxiaoyu.spring.test1"></context:component-scan> <!-- use-default-filters="false"表示現在不使用預設filter,自己配置filter context:include-filter:設定掃描哪些內容 --> <context:component-scan base-package="com.orzjiangxiaoyu.spring" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- context:exclude-filter設定哪些內容不掃描 --> <context:component-scan base-package="com.orzjiangxiaoyu.spring"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> </beans>