Spring配置文件(xml)中的xmlns解析

以前一直没注意spring对xml的解析过程,
特别是xml文件头上的一堆xmlns:

这些命名空间中是怎么解析的,
大概可以分为下面这个步骤:
1. 解析XML, 找到所有的 命名空间 如: http://www.springframework.org/schema/context
2. 在Classpath中查找所有的 spring.handlers 并解析其中配置的 命名空间 与 对应的处理类, 如:

http\://www.springframework.org/schema/aop=org.springframework.aop.config.AopNamespaceHandler

3. 根据查找到的处理Handler去解析配置文件中相应的结点.

而命名空间对应的xsd文件, 则是在 spring.schemas 中指定的, 如:

http\://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd
http\://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd
http\://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop-3.0.xsd
http\://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-3.0.xsd

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基本的spring-mvc.xml配置文件模板: ```xml <?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: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/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"> <!-- 配置Spring MVC 的 DispatcherServlet --> <mvc:annotation-driven/> <mvc:default-servlet-handler/> <!-- 配置静态资源的路径 --> <mvc:resources mapping="/static/**" location="/static/"/> <!-- 配置视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 配置扫描Controller包 --> <context:component-scan base-package="com.example.controller"/> </beans> ``` 其: - `<mvc:annotation-driven/>` 表示启用Spring MVC的注解驱动,可以使用 `@Controller`、`@RequestMapping`等注解。 - `<mvc:default-servlet-handler/>` 表示将静态资源的请求交给Servlet容器处理。 - `<mvc:resources>` 用于配置静态资源的路径,mapping属性表示访问路径,location属性表示资源文件所在路径。 - `<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">` 表示配置JSP视图解析器,prefix属性表示JSP文件所在路径的前缀,suffix属性表示JSP文件的后缀。 - `<context:component-scan base-package="com.example.controller"/>` 表示扫描指定的包,查找带有注解的类,例如 `@Controller`、`@Service`等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值