1

I am facing a lot of issues one after the other. Let me note it down properly -

I am implementing Springframework cache and this was my original SpringCacheConfig.xml -

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:cache="http://www.springframework.org/schema/cache"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:c="http://www.springframework.org/schema/c"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:hz="http://www.hazelcast.com/schema/spring"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                       http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                       http://www.hazelcast.com/schema/spring http://www.hazelcast.com/schema/spring/hazelcast-spring.xsd"> 

This was working fine in my laptop, but in the test VM, we were not able to download the XSD schema files from internet.

So I changed the schemalocations to classpath -

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:cache="http://www.springframework.org/schema/cache"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:c="http://www.springframework.org/schema/c"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:hz="http://www.hazelcast.com/schema/spring"
   xsi:schemaLocation="http://www.springframework.org/schema/beans classpath:spring-beans.xsd
                       http://www.springframework.org/schema/cache classpath:spring-cache.xsd
                       http://www.springframework.org/schema/context classpath:spring-context.xsd
                       http://www.hazelcast.com/schema/spring classpath:hazelcast-spring.xsd">

So now the XSD files were picked up. But the downloaded spring-context.xsd file has the following content -

<xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="https://www.springframework.org/schema/beans/spring-beans-4.3.xsd"/>
<xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="https://www.springframework.org/schema/tool/spring-tool-4.3.xsd"/>

So I have again moved them to classpath.

After these changes if I now execute our code, I am getting the following error -

Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
    Offending resource: class path resource [SpringCacheConfig.xml]

I tried to solve this problem by many previous posts, but not able to.

The pom is already including spring-context related jars -

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${springframework.version}</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${springframework.version}</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${springframework.version}</version>
</dependency>

These jars are not packaged within the main jar, but are available at

modules/system/layers/thirdparty/org/springframework/main/spring-context-4.3.1.RELEASE.jar.

But why the jar couldn't be found?

I also tried the shade plugin, but still dependency jars are not included - How to create spring-based executable jar with maven?

What else should I think about?

I don't have the META-INF/spring.handlers etc Spring related files within the jar. Can it be the issue?

Nirmalya
  • 398
  • 5
  • 19
  • 1
    Those files should be loaded from the Spring framework jars and not the internet. Hence I would say that you aren't using the regular Spring jars but modified ones (maybe a fat-jar or something alike, at least something you aren't explaining here). – M. Deinum Apr 09 '19 at 17:54
  • Hi Deinum, I meant I downloaded the XSD files from internet and not the jars. And spring-context-4.3.1.RELEASE.jar was taken from maven. The actual problem was with the spring.handlers and spring.schemas files; these files should be placed under META-INF. Thanks. – Nirmalya Apr 12 '19 at 09:29

1 Answers1

1

I solved the problem by creating a META-INF directory and putting the spring.handlers and spring.schemas files into it. I extracted all the spring jars, some of them have these spring.handlers and spring.schemas files. I concatenated the contents of those files and put them in META-INF.

But surprisingly, the project was working in eclipse, but not in VM. In eclipse project, I don't need to copy the spring.handlers and spring.schemas files in the jar's META-INF directory - it works without them. But in VM I need to copy the files! May be in eclipse these files are referred from .m2, since those jars are in the classpath? Any idea?

Thanks

Nirmalya
  • 398
  • 5
  • 19
  • The fact that you are doing this makes me wonder what you are actually doing. There is something you aren't explaining in your question as this is something you shouldn't be doing... – M. Deinum Apr 15 '19 at 05:29
  • Hi @M.Deinum: Sorry for late reply. Let me clarify once again. I am just implementing Springframework cache. We don't have Internet in our VM docker container, so we are keeping the xsd files in the classpath. All the relevant spring jar files are present in the classpath. But when I am executing the program it gives the following error - `Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context] Offending resource: class path resource [SpringCacheConfig.xml]`. Do you know how to fix this issue? – Nirmalya Apr 20 '19 at 18:08
  • 1
    And elt me clarify again that you don't need the XSD files. Those are already in the jar and the default setup will retrieve them from the jar. Hence you aren't using a default setup. So you aren't explaining or clarifying everything in your question and you are leaving out crucial details. – M. Deinum Apr 21 '19 at 07:08
  • Looks like you are creating a fatjar or something like that in stead of a regular war or whatever you use. – M. Deinum Apr 21 '19 at 07:18
  • Hi @M.Deinum: thanks for pointing out the mistake! Since we are depending on module.xml for runtime deployment of jars, we had to add the following entry in module.xml - ` ` With this change all the jars are now available in the classpath and the xsd files contained within the jar files are also picked up. So we don't need to do anything manually. Thanks for your help in finding out the root cause. – Nirmalya May 15 '19 at 10:37