需要了解 spring.handlers 和 spring.schemas [英] Need understanding of spring.handlers and spring.schemas

查看:26
本文介绍了需要了解 spring.handlers 和 spring.schemas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题源于我已经通过 其他问题.但是,我仍然想知道根本原因.我的问题如下:

I have some questions derived from a problem that I have already solved through this other question. However, I am still wondering about the root cause. My questions are as follows:

  1. spring.handlersspring.schemas 的用途是什么?
  1. What is the purpose of spring.handlers and spring.schemas?

据我了解,这是一种告诉 Spring 框架在哪里定位 xsd 的方式,以便正确连接和加载所有内容.但是……

As I understand it's a way of telling the Spring Framework where to locate the xsd so that everything is wired and loaded correctly. But...

  1. 什么情况下我应该在META-INF文件夹下有这两个文件?

  1. Under what circumstances should I have those two files under the META-INF folder?

在我上面链接的另一个问题中,有人知道为什么我必须添加 maven-shade-plugin 来在 META-INF 下创建这两个文件(基于我的所有依赖项)?换句话说,让我不得不使用 maven shade 插件的根本原因是什么?

In my other question linked above, does anybody know why I had to add the maven-shade-plugin to create those two files (based on all my dependencies) under META-INF? In other words, what was the ROOT CAUSE that made me have to use the maven shade plugin?

推荐答案

spring.handlers 和 spring.schemas 的作用是什么?

What is the purpose of spring.handlers and spring.schemas?

好吧,您或多或少是您自己发现的,让我们添加更多细节:

well you more or less found it out by yourself, let's add some more details:

一些 spring 库包含一个 spring.schemas 和 spring.handlers 文件 在 META-INF 目录中

some spring libraries contain a spring.schemas and a spring.handlers file inside a META-INF directory

META-INF/spring.schemas

  • 将架构位置重新映射 (*) 到库内的 xsd
  • (抽象)此库仅支持重新映射的版本

META-INF/spring.handlers

  • 为特定命名空间提供命名空间处理程序类
  • 命名空间处理程序类提供解析器逻辑来解析 spring-batch bean,如 job步骤

(*) 实际的重新映射发生在 Spring 应用程序上下文的构建过程中

(*) the actual re-mapping happens during the build of the spring application context

什么情况下我应该把这两个文件放在META-INF 文件夹?

Under what circumstances should I have those two files under the META-INF folder?

通常文件在你使用的spring库jar中,但你可以使用该机制来实现自己的命名空间bean解析,那么你就会有自己的文件

normally the files are inside the spring library jars you use, but you can use the mechanism to implement own namespace bean parsing, then you would have own files

在我上面链接的另一个问题中,有人知道我为什么必须添加maven-shade-plugin 来创建这两个文件(基于我所有的依赖项)在 META-INF 下?换句话说,根本原因是什么这让我不得不使用 maven shade 插件?

In my other question linked above, does anybody know why I had to add the maven-shade-plugin to create those two files (based on all my dependencies) under META-INF? In other words, what was the ROOT CAUSE that made me have to use the maven shade plugin?

如果您在 spring 配置中使用 spring 命名空间,则需要相应的文件

if you use a spring namespace in your spring configuration, you need the appropriate files

当你想运行一个java应用程序时,问题就出现了:

the problem arises when you want to run a java application:

  • 有一个主类
    • spring 库需要在类路径中
    • 或全部合并到一个 jar 中,该 jar 必须在类路径中 (*)

    我猜你没有用完整的类路径启动主类,我也为你的第一个问题更新了我的答案

    i guess you did not start the mainclass with the complete classpath and i updated my answer for your first question too

    (*) 如果将所有内容合并到一个 jar 中,则必须确保所有 spring.schemas/spring.handlers 文件的内容都合并到一个 spring.schemas 和一个 spring.handlers 文件中,请参阅此 回答配置maven 创建一个 all-in-one.jar

    (*) if you merge all into one jar, you have to make sure, that the contents of all spring.schemas/spring.handlers files are merged into one spring.schemas and one spring.handlers file, see this answer for a configuration with maven to create an all-in-one.jar

    这篇关于需要了解 spring.handlers 和 spring.schemas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆