需要了解 spring.handlers 和 spring.schemas

发布于 2024-12-22 08:22:26 字数 584 浏览 2 评论 0原文

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

  1. spring.handlersspring.schemas 的目的是什么?

据我了解,这是一种告诉 Spring 框架在哪里找到 xsd 的方法,以便所有内容都正确连接和加载。但是...

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

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

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. What is the purpose of spring.handlers and spring.schemas?

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. Under what circumstances should I have those two files under the META-INF folder?

  2. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稚气少女 2024-12-29 08:22:26

spring.handlers 和 spring.schemas 的目的是什么?

好吧,你或多或少自己发现了它,让我们添加更多细节:

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

META-INF/spring.schemas

  • 重新映射(*) schemalocation 到库内的 xsd
  • (抽象) 该库仅支持重新映射的版本

META-INF/spring.handlers

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

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


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

通常这些文件位于您使用的 spring 库 jar 中,但是您可以使用该机制来实现自己的命名空间 bean 解析,那么您将拥有自己的文件


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

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

当您想要运行 java 应用程序时就会出现问题:

  • 使用主类
    • spring 库需要位于类路径上
    • 或者全部合并到一个 jar 中,该 jar 必须位于类路径 (*)
  • 作为 war/ear 服务器应用程序位于类路径(*)上,spring 库需要位于类路径上,

我猜 通常在 war 内您没有使用完整的类路径启动主类,如果您合并,我也更新了您第一个问题的答案

(*)合而为一jar,您必须确保所有 spring.schemas/spring.handlers 文件的内容都合并为一个 spring.schemas 和一个 spring.handlers 文件,请参阅此 答案使用 maven 配置来创建 all-in-one.jar

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:

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

META-INF/spring.schemas

  • re-maps(*) schemalocation to a xsd inside the library
  • (abstract) only re-mapped versions are supported by this library

META-INF/spring.handlers

  • provides namespace handler classes for specific namespaces
  • the namespace handler class provides the parser logic to parse spring-batch beans, like job,
    step, etc.

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


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

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


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?

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

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

  • with a main class either
    • the spring libraries need to be on the classpath
    • or all is merged into one jar, which has to be on the classpath (*)
  • as war/ear server application, the spring libaries need to be on the classpath, normally inside the war

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

(*) 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文