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. swing jTable排序问题(点击表头排序)

    1.JDK6自带排序实现: tableName.setAutoCreateRowSorter(true); 2.其实界面设计中勾选一个属性就搞定了: .

  2. Windows10环境中 laravel任务调度 如何启动调度

    Windows10环境中 laravel任务调度 如何启动调度 一:问题由来 1:今天在做用laravel开发订单系统的时候,需要使用定时任务来大批量提交订单,测试一下订单金额是否有误.发现larav ...

  3. JavaScriptav数据类型和变量

    数据类型 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同的数据,需要定 ...

  4. PHP 优秀资源汇集(照搬)

    文章目录 原文地址: https://shockerli.net/post/php-awesome/ GitHub: https://github.com/shockerli/php-awesome ...

  5. CodeFrist基础_Fluent Api

    一丶首先新建两个实体类 public class Student { public int StudentKey { get; set; } public string StudentName { g ...

  6. JAVA基础——文件File简单实用

    1.1java.io.File File用于表示文件系统中的一个文件或目录 通过File可以: 1:访问该文件或目录的属性信息(名字,大小,修改时间等) file.getName();获取文件名fil ...

  7. no bundle URL present in react-native?

    Assuming that you are using nvm and multiple versions of node installed, here is the solution: Say t ...

  8. UVA - 12589 Learning Vector(dp-01背包)

    题目: 思路: dp[j][h]表示选取了j个向量,且高度为h,利用01背包来解决问题. 没选当前的向量:dp[j][h] = dp[j][h]; 选了当前的向量:dp[j][h] = dp[j-1] ...

  9. Humidex POJ - 3299 (数学)

    题目大意 给定你三个变量中的两个输出剩下的那一个 题解 没有什么,就是把公式推出来即可,完全的数学题 代码 #include <iostream> #include <cmath&g ...

  10. Word2Vec的基本使用

    目录 1.建立模型 2.保存与加载模型 3.使用模型 gensim 是 Python 中一款强大的 自然语言处理工具,它包含了常见的模型,其中便有 Word2Vec 这一优秀的 词向量训练工具,可以使 ...