zoukankan      html  css  js  c++  java
  • Spring 使用注解注入 学习(四)

    <?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.xsd">
    
        <context:component-scan base-package="org.example"/>
    
    </beans>
    @Configuration
    @ComponentScan(basePackages = "org.example")
    public class AppConfig  {
        ...
    }
    The use of <context:component-scan> implicitly enables the functionality of <context:annotation-config>. There is usually no need to include the <context:annotation-config> element when using <context:component-scan>.
    当在组件类上使用了特定的注解之后, 还需要在 Spring 的配置文件中声明 <context:component-scan>base-package 属性指定一个需要扫描的基类包,Spring 容器将会扫描这个基类包里及其子包中的所有类. 
    当需要扫描多个包时, 可以使用逗号分隔.
    如果仅希望扫描特定的类而非基包下的所有类,可使用 resource-pattern 属性过滤特定的类,示例:
    
    <context:include-filter> 子节点表示要包含的目标类
    <context:exclude-filter> 子节点表示要排除在外的目标类
    <context:component-scan> 下可以拥有若干个 <context:include-filter> 和 <context:exclude-filter> 子节点

    You can also disable the default filters by setting useDefaultFilters=false on the annotation or providing use-default-filters="false" as an attribute of the <component-scan/> element. This will in effect disable automatic detection of classes annotated with @Component@Repository@Service@Controller, or @Configuration.
  • 相关阅读:
    实验四 决策树算法及应用
    实验三 朴素贝叶斯算法及应用
    实验二 K-近邻算法及应用
    实验一 感知器及其应用
    实验三 面向对象分析与设计
    实验二 结构化分析与设计
    实验一 软件开发文档与工具的安装与使用
    个人作业三-ATM管理系统
    个人作业二-举例分析流程图与活动图的区别与联系
    第一次个人作业-四则运算题目生成程序(计算机181 张博闻)
  • 原文地址:https://www.cnblogs.com/mengjianzhou/p/9131554.html
Copyright © 2011-2022 走看看