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. tensorboard在windows系统浏览器显示空白的解决

    一个简单的using_tensorboard.py程序,如下: #using_tensorboard.py import tensorflow as tf a = tf.constant(10,nam ...

  2. Quartus 12的TimeQuest Timing Analyzer

    Quartus 12的TimeQuest Timing Analyzer 1.在Quartus II软件打开和设置设计 安装路径下\qdesigns\fir_fliter文件.在Processing ...

  3. Codeforces_768_D_(概率dp)

    D. Jon and Orbs time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. DeepCloneObjects 和 DeepClone

    ARX AcDbDatabase 中的方法 deepCloneObjects() 和 wblock() 区别以及和 AcDbObject 方法 clone() 和 deepClone() 的关系 Ac ...

  5. js统计图表插件 Echarts

    Echarts 用于制作数据统计图表,一个纯 Javascript 的图表库,快捷简便的生成统计图表. 官网:https://www.echartsjs.com/ 效果 html <!DOCTY ...

  6. thymeleaf在开发环境正常,但用jar运行时报错 Error resolving template template might not exist or might not be accessible

    解决方案: (1)配置中添加  spring.thymeleaf.prefix=classpath:/templates (2)指向模板的路径 不加 /

  7. 利用gsoap库封装易用的rest框架

    c++缺少web开发的框架,web框架分为异步和同步,异步的业务逻辑控制需要较强功底,同步代码实现起来容易,利于阅读理解 1.gsoap是c++写的webservice库,webservice应用层也 ...

  8. 【Python实践-9】将字符串转化为浮点型

    利用map和reduce编写一个str2float函数,把字符串'123.456'转换成浮点数123.456. 思路:计算小数位数--->将字符串中的小数点去掉--->字符串转换为整数-- ...

  9. PAT 1141 PAT Ranking of Institutions

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  10. 47. Spring Boot发送邮件【从零开始学Spring Boot】

    (提供源代码) Spring提供了非常好用的JavaMailSender接口实现邮件发送.在Spring Boot的Starter模块中也为此提供了自动化配置.下面通过实例看看如何在Spring Bo ...