Spring通過註解配置bean的xml文件
阿新 • • 發佈:2019-02-18
<?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: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-4.3.xsd"> <!-- 指定spring IOC容器掃描的包 --> <!-- 可以通過resource-pattern指定掃描的資源 <context:component-scan base-package="com.spring.annotation" resource-pattern="repository/*.class"> </context:component-scan> --> <context:component-scan base-package="com.spring.annotation" use-default-filters="false"> <!-- context:exclude-filter子節點指定排除哪些表示式的元件 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/> --> <!-- context:include-filter子節點指定只包含哪些表示式的元件,需要配合use-default-filters="false"來用 <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/> --> <!-- type="assignable"是根據類名來指定,用法和上面一樣 <context:include-filter type="assignable" expression="com.spring.annotation.repository.UserRepository"/> --> </context:component-scan> </beans>