美文网首页
使用Spring开发中常用的xml配置文件的命名空间

使用Spring开发中常用的xml配置文件的命名空间

作者: pankx | 来源:发表于2020-03-09 21:44 被阅读0次

引言

    在使用Spring框架的日常开发当中使用xml文件配置方式配置的spring的话,会遇到一个问题,那就是配置文件的命名空间太多太长记不住,因此在此总结一些常用的命名空间。

如果只使用Sping的ioc可以使用下面的命名空间

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    如果要支持Spring 的AOP的功能只须在ioc命名基础上加上aop的命名空间即可,如下列代码

<?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:aop="http://www.springframework.org/schema/aop"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd">

    如果要使用Spring的事务控制,只须在aop命名基础上加上事务控制的的命名空间tx即可,如下列代码

<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">

    SpringMVC的xml命令空间如下


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    MyBatis的命名空间如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
      PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
      "http://mybatis.org/dtd/mybatis-3-config.dtd">

    ssm三个框架整合开发Spring配置文件的命名空间如下


<?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"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">

总结:实际开发中spring的注解方式相比较于xml文件配置方式简单,可根据需求选择

相关文章

  • Spring 切面解析过程

    当使用Spring事务时,需要在Spring的配置文件中添加命名空间aop aop命名空间的处理类可在Spring...

  • 使用Spring开发中常用的xml配置文件的命名空间

    引言 在使用Spring框架的日常开发当中使用xml文件配置方式配置的spring的话,会遇到一个问题,那就是配置...

  • XML-schema

    首先来看一下项目中spring的一个配置文件 XML Schema命名空间作用: 1、避免命名冲突,像Java中的...

  • SpringCore

    Spring core 1.IOC容器 (1) bean 使用注解代替XML: 命名空间:

  • spring aop 通知

    Spring aop 导入Spring aop基本jar包,使用的aspectj 配置文件引入命名空间,配置a...

  • Spring讲解(四)

    Spring 中使用注解注入 注解:就是一个类,使用 @ 注解名称。实际开发中:使用注解取代 xml 配置文件。 ...

  • Spring使用AspectJ进行AOP开发(基于注解)

    在 Spring 中,虽然我们可以使用 XML 配置文件可以实现 AOP 开发,但如果所有的配置都集中在 XML ...

  • 命名空间装配

    待装配bean 普通装配 命名空间装配 c-命名空间是在 Spring 3.0 中引入的,它是在 XML 中更为简...

  • 通过Spring Boot快速搭建RESTful服务

    使用Spring框架开发Java应用时,需要写大量的xml配置文件,Spring Boot使用了大量的Java配置...

  • Spring常用注解配置

    准备工作 applicationContext.xml 添加命名空间和约束,适用于xml和注解同时使用 常用注解 ...

网友评论

      本文标题:使用Spring开发中常用的xml配置文件的命名空间

      本文链接:https://www.haomeiwen.com/subject/ztwmdhtx.html