Need understanding of spring.handlers and spring.schemas

前端 未结 1 881
一生所求
一生所求 2020-12-08 16:17

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

相关标签:
1条回答
  • 2020-12-08 16:37

    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

    0 讨论(0)
提交回复
热议问题