Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

xsd - Need understanding of spring.handlers and 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. 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...