zoukankan      html  css  js  c++  java
  • [转]spring学习笔记:annotation的使用1

    摘自wjt276的笔记
    --------------

    annotation方式Spring

    一、       开始使用annotation配置Spring

    首先需要在springxml配置文件中加入下列红色加粗部分的代码。

    <?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-2.5.xsd

               http://www.springframework.org/schema/context

               http://www.springframework.org/schema/context/spring-context-2.5.xsd">           

        <context:annotation-config/>

    </beans>

     

    这样当spring加载配置文件时,发现有<context:annotation-config/>标签后,会帮我加载以下四个类(用于处理annotation方式的配置):

        1AutowiredAnnotationBeanPostProcessor,

        2CommonAnnotationBeanPostProcessor,

    3PersistenceAnnotationBeanPostProcessor,

        4RequiredAnnotationBeanPostProcessor

     

    xmlns=http://www.springframework.org/schema/beans

    表示xml中没有前缀的标签,使用的命名规范为http://www.springframework.org/schema/beans对应的内容. 如果eclipse中没有配置.则会自动上网下载.

    Eclipse中配置如下:

     

    如图, key即为xmlns=http://www.springframework.org/schema/beans 配置的url地址.

    对应Schema location 即为本地的xsd文件.文件中含有key的标识,以及xml规范的定义.

     

    同理:

    xmlns:context="http://www.springframework.org/schema/context"

    配置的是 context开头的标签的规则. 如下图

     

    xsi:schemaLocation中配置是xsi开头对应的规则locationxsd文件名 (本地的xsd包含对应标识)


  • 相关阅读:
    方法
    成员变量和局部变量
    带参数的方法
    包名规范
    String
    导包
    java基础(十二章)
    java基础(十一章)
    java基础(九章)
    java基础(八章)
  • 原文地址:https://www.cnblogs.com/redcoatjk/p/3562368.html
Copyright © 2011-2022 走看看