1、InitializingBean

  Spring设置完一个bean的合作者后,会检查bean是否实现InitializingBean接口,实现的话会调用afterPropertiesSet(InitializingBean的唯一方法)方法,将某些数据加载到缓存中(如数据字典等不经常会改变的一些数据)。

2、<context:component-scan>使用说明

   在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类注册为bean。

 

  <!-- 自动扫描且只扫描@Controller -->
  <context:component-scan base-package="com.coracle" use-default-filters="false">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
  </context:component-scan>

  use-default-filters="false"表示不要使用默认的过滤器,而使用<context:exclude-filter>。

  <context:exclude-filter>标签作用缩小扫描粒度,如上图配置只扫描所有带@Controller注解的java类,并注册成bean(use-default-filters="true"时不起作用,默认为true)。

3、SpringMVC和Spring各自扫描自己的注解不要互相混淆

  3.1web.xml中springMVC相关部分

  <!-- Spring MVC Servlet -->
  <servlet>
    <servlet-name>springServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  3.2 mvc.xml文件中关键部分

   <!-- 开启springMVC注解支持 -->
        <mvc:annotation-driven />

  <!-- 容器默认的DefaultServletHandler用于处理所有静态内容与无RequestMapping处理的URL-->
        <mvc:default-servlet-handler/>

  <!-- 自动扫描且只扫描@Controller -->
  <context:component-scan base-package="com.coracle" use-default-filters="false">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
  </context:component-scan>

     3.3 web.xml中spring容器关键部分   

  <!-- Spring ApplicationContext配置文件的路径,可使用通配符,用于后面的Spring Context Loader -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:/applicationContext.xml,classpath*:/applicationContext-shiro.xml</param-value>
  </context-param>

  

   3.4 spring-core.xml文件关键部分

  <!-- 使用annotation定义事务 -->
  <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> 

  <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
  <context:component-scan base-package="com.coracle">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
  </context:component-scan>

  

Spring自我总结的更多相关文章

  1. Preview of Spring-framework :Spring框架的预习和自我整理

    Spring简介 - 预习的自我整理 1. What's Spring? Spring是一个从实际开发中抽取出来的框架,完成了大量开发中的通用步骤,留给开发者仅仅是与特定应用相关的部分,从而提高了企业 ...

  2. 自我分析-Spring IOC

    Spring IOC容器实现原理大致是容器(Map)+反射(Java反射和cglib).Spring提供丰富的ApplicationContext.以FileSystemXmlApplicationC ...

  3. 【转帖】如何利用Spring Cloud构建起自我修复型分布式系统

    http://zhidao.baidu.com/link?url=tSKwdn3wr8KUxWMteHmneFtY0KoNZBMK9Xy-RimsdISA4h2neAecgHqggBipz2w6nXr ...

  4. 【spring源码学习】spring的aop目标对象中进行自我调用,且需要实施相应的事务定义的解决方案

    转载:http://www.iteye.com/topic/1122740 1.预备知识 aop概念请参考[http://www.iteye.com/topic/1122401]和[http://ji ...

  5. 全栈的自我修养: 001环境搭建 (使用Vue,Spring Boot,Flask,Django 完成Vue前后端分离开发)

    全栈的自我修养: 环境搭建 Not all those who wander are lost. 彷徨者并非都迷失方向. Table of Contents @ 目录 前言 环境准备 nodejs v ...

  6. Spring事务处理时自我调用

    1.预备知识 aop概念请参考[http://www.iteye.com/topic/1122401]和[http://jinnianshilongnian.iteye.com/blog/141859 ...

  7. Spring Cloud Eureka 之服务端自我注册

    Eureka服务端实现了一种自我注册机制,涉及配置项: eureka.client.register-with-eureka spring.application.name Eureka Server ...

  8. Spring事务处理时自我调用的解决方案 嵌套AOP

    开涛的解决方案1 http://jinnianshilongnian.iteye.com/blog/1487235 AopContext.currentProxy() 原理 http://books. ...

  9. Spring中Adivisor和Aspect的差别(自我理解)

    在AOP中有几个概念: - 方/切 面(Aspect):一个关注点的模块化,这个关注点实现可能另外横切多个对象.事务管理是J2EE应用中一个非常好的横切关注点样例. 方面用Spring的Advisor ...

随机推荐

  1. taskctl命令行类(sh、exe、python新增scp)插件升级扩展

    转载自: http://www.taskctl.com/forum/detail_129.html 上次写了一个帖子 TASKCTL中不使用代理,通过ssh免密连接执行远程脚本配置(SSH插件扩展)h ...

  2. GetArxPath

    extern HINSTANCE _hdllInstance;CString GetArxPath(){ CString strArxPath; GetModuleFileName(_hdllInst ...

  3. 梦想CAD控件COM接口搜索图面上的文字

    点击此处下载演示实例 主要用到函数说明: _DMxDrawX::NewSelectionSet 实例化一个构造选择集进行过滤,该类封装了选择集及其处理函数. _DMxDrawX::NewResbuf ...

  4. java Object类中方法介绍

  5. Django - 模版之继承

    模版继承: 当多个html有共同之处时,需要建立一个模版html(master.html) 1.在模版html中,写入公共的部分: 备注:在模版中,我们可以指定多个block ,其中,可以在标题,cs ...

  6. Python 爬虫爬取今日头条街拍上的图片

    # 今日头条--街拍 import requests from urllib.parse import urlencode import os from hashlib import md5 from ...

  7. 08css、JS

    08.css.JS-2018/07/18 1.css的属性 文字属性:font-size:大小,font-family字体类型,font-color:颜色 文本颜色:color:颜色,test-dec ...

  8. Gym - 101670E Forest Picture (CTU Open Contest 2017 模拟)

    题目: https://cn.vjudge.net/problem/1451310/origin 题意&思路: 纯粹模拟. 大体题意是这样的: 1.有人要在一个10-9<=x<=1 ...

  9. ubuntu wsl 子系统使用win10 系统ss代理步骤

    wind10 安装ss客户端 配置server 具体不多说 安装 ubuntu 子系统 3.安装python pip apt install python-pip 4.升级pip pip instal ...

  10. Python随笔day03

    温故知新: 注释: 单行注释   # 多行注释   ‘’’ ‘’’  或者  “””  “”” 注意:三个单引号或双引号可以用于表示多行字符串. 判断输入的字符串是否是数字 salary = inpu ...