Skip to content

Document Spring recommendations/restrictions for Java 9 module setups [SPR-14579] #19148

Closed
@spring-projects-issues

Description

@spring-projects-issues

Paul Bakker opened SPR-14579 and commented

As part of the work I'm doing for the upcoming Java 9 book for O'Reilly I'm experimenting with migration scenarios towards Java 9 modules.

The scenario is the following. The user migrated her code to a module (meaning that a module-info.java was added). The code relies on a Spring version which is not yet Java 9 compatible. This should't be a problem, because existing libraries should be able to work as "automatic modules". This works well with Spring, up until the point that namespaces in the xml configuration are used.

<context:component-scan base-package="org.example"/>

This results in the following error:

Exception in thread "main" 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 [services.xml]

	at org.springframework.beans.factory.parsing.FailFastProblemReporter.error([email protected]/FailFastProblemReporter.java:70)
	at org.springframework.beans.factory.parsing.ReaderContext.error([email protected]/ReaderContext.java:85)
	at org.springframework.beans.factory.parsing.ReaderContext.error([email protected]/ReaderContext.java:80)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error([email protected]/BeanDefinitionParserDelegate.java:301)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement([email protected]/BeanDefinitionParserDelegate.java:1408)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement([email protected]/BeanDefinitionParserDelegate.java:1401)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions([email protected]/DefaultBeanDefinitionDocumentReader.java:172)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions([email protected]/DefaultBeanDefinitionDocumentReader.java:142)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions([email protected]/DefaultBeanDefinitionDocumentReader.java:94)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions([email protected]/XmlBeanDefinitionReader.java:508)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions([email protected]/XmlBeanDefinitionReader.java:392)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions([email protected]/XmlBeanDefinitionReader.java:336)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions([email protected]/XmlBeanDefinitionReader.java:304)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions([email protected]/AbstractBeanDefinitionReader.java:181)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions([email protected]/AbstractBeanDefinitionReader.java:217)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions([email protected]/AbstractBeanDefinitionReader.java:188)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions([email protected]/AbstractBeanDefinitionReader.java:252)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions([email protected]/AbstractXmlApplicationContext.java:127)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions([email protected]/AbstractXmlApplicationContext.java:93)
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory([email protected]/AbstractRefreshableApplicationContext.java:129)
	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory([email protected]/AbstractApplicationContext.java:612)
	at org.springframework.context.support.AbstractApplicationContext.refresh([email protected]/AbstractApplicationContext.java:513)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>([email protected]/ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>([email protected]/ClassPathXmlApplicationContext.java:93)
	at demo.bootstrapper.Main.setup(bootstrap/Main.java:11)
	at demo.bootstrapper.Main.main(bootstrap/Main.java:16)

I'm not suggesting this is an error in Spring, or that this must be fixed, but hopefully it's useful information for compatibility issues in the future.

A (pretty bad) workaround is to extract the META-INF folder from the JAR file and put that on the classpath.


Affects: 5.0 M1

Issue Links:

Referenced from: commits 6ef7dd4

0 votes, 9 watchers

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions