zoukankan      html  css  js  c++  java
  • Bean的定义及作用域的注解实现

    1. Classpath扫描与组件管理

    从Spring3.0开始,Spring JavaConfig项目提供了很多特性,包括使用java而不是XML定义bean。

    比如@configuration, @Bean, @Import, @DependsOn

    @Component是一个通用注解,可用于任何Bean

    @Repository, @Service, @Controller是更有针对性的注解

    ——@Repository通常用于注解DAO类,即持久层

    ——@Service通常用于注解Service类,即服务层

    ——@Controller通常用于Controller类,即控制层(MVC)

    2. 类的自动检测与注册Bean

    Spring可以自动检测类并注册Bean到ApplicationContext中

    3. <context:annotation-config/>

    通过基于XML的Spring配置标签

    <context:annotation-config/>仅会查找在同一个applicationContext中的bean注解

    1 <?xml version="1.0" encoding="UTF-8"?>
    2 <beans xmlns="http://www.springframework.org/schema/beans" 
    3   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    4   xsi:schemaLocation="http://www.springframework.org/schema/beans/beans.xsd http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    5 
    6     <context:annotation-config/>
    7 
    8 </beans>

    4. @Component, @Repository, @Service, @Controller

    5. @Required

    6. @Autowired

    7. @Qualifier

    8. @Resource

  • 相关阅读:
    MongoDB
    Vivado HLS与System Generator:联系与区别
    FPGA的图像处理技术,你知道多少?
    增量与位置PID
    zedboard之GPIO驱动(从FPGA一直到LINUX应用)
    珠峰攀登记录
    Source Insight建工程之Kernel
    zedboard 驱动理解
    研一上学期总结以及规划
    数字图象处理MATLAB学习
  • 原文地址:https://www.cnblogs.com/BlackList-Sakura/p/4403015.html
Copyright © 2011-2022 走看看