-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document Spring recommendations/restrictions for Java 9 module setups [SPR-14579] #19148
Comments
Juergen Hoeller commented Hey Paul, We are tracking JDK 9 compatibility for Spring 5: As of 5.0 M1, the test suite passes on JDK 9 in classpath mode (#17928). For use on the module path, we attempt to sort out the automatic modules option for 5.0 M3 (#18289). As for finding the schemas, I suppose this only applies when actually using XML bean definitions? That is, not when using configuration classes or plain programmatic registration? Also, I recall some recent discussions on the Jigsaw mailing list about the exposure of resources. This might be something worth addressing there, asking for default exposure of classpath resources from automatic modules. |
Paul Bakker commented That's correct. The issue is related to the changes to resource loading (http://mail.openjdk.java.net/pipermail/jpms-spec-experts/2015-October/000163.html). The "getResource*" methods don't find resources in modules. A new reflection API is available to iterate over modules and a module's resources. |
Juergen Hoeller commented Mark Reinhold's latest proposal suggests getting rid of resource encapsulation altogether: http://openjdk.java.net/projects/jigsaw/spec/issues/#ResourceEncapsulation. And as far as I remember, the idea was that automatic modules would see all resources in any case. This doesn't seem to be available in the mainline yet but is apparently changed in the Jigsaw branch: https://jdk9.java.net/jigsaw/. |
Paul Bakker commented If I'm not mistaken (I'm just trying to get through the Spring codebase) the same problem exists for component scanning. E.g. a component scan like the one below ultimately uses ClassLoader.getResources, which doesn't currently return resources in named modules (in this case class files).
If this requirement is dropped as being discussed on the mailing list that should work again as well I assume. |
Paul Bakker commented Hi Jurgen, I retested with a Java 9 build that includes the dropped resource constraints things look a lot better! If I create a "modular JAR" containing the service that needs to be picked up by the component scan, it works. If I run in "exploded" mode however, it doesn't. In case you're interested in further debugging, I pushed the setup to a git repo: https://github.com/paulbakker/spring-java9. |
Juergen Hoeller commented Thanks for your efforts, Paul! That's great to hear, and I hope it'll get merged into the JDK 9 mainline soon. I wasn't aware of the "exploded" mode at all. So this means that |
Juergen Hoeller commented Paul Bakker, since we're about to revisit this from our side: Have you had any success with post-August JDK 9 builds? We're still waiting for CGLIB 3.2.5 for a JDK 9 compatible |
Paul Bakker commented Newer builds are a lot better when it comes to framework compatibility. See this Devoxx presentation (second part) about migrating a (old fashioned) Spring/Hibernate application. You can find the example source code here: https://github.com/sandermak/java9-migration-demos/tree/master/4_ModularSpring |
Juergen Hoeller commented As far as my research goes, the problem is that I've reported this to the jigsaw-dev list since there is nothing we can do about it from our end. |
Juergen Hoeller commented Paul Bakker, it looks your sample application from back in November got away with just declaring |
Paul Bakker commented I've recently given an updated version of this talk again at DevoxxUS: https://www.youtube.com/watch?v=TEoexFsDP6A. tl;dr: Spring is doing fine as automatic modules. No changes to how transitive dependencies work either. Any progress with moving to named modules? |
Juergen Hoeller commented Thanks for the update, that's good to hear! As for explicit module declarations, we're tracking this in #18079. Unfortunately, according to the latest discussions around Jigsaw and Mark Reinhold's recent statements, it is absolutely not recommended to bake automatic module names for third-party dependencies into higher-level module descriptors. This means that we have to wait for all of our (optional) dependencies to ship module descriptors first, which single-handedly moves our target date to 2019+, possibly into Spring 6 :-( For the time being, we'll have to keep focusing on the use of our framework jars as automatic modules. We might ship some aggregator modules with Jigsaw metadata (i.e. empty jars with just a |
Paul Bakker commented Might be worth sharing that feedback on the mailing list. I understand the fundamental point they are making, but making it almost impossible to migrate frameworks to modules is a serious problem. |
Juergen Hoeller commented Good point - done :-) We are nevertheless supportive of Jigsaw even in Spring 5.x, just with a focus on automatic modules for the time being. I guess Spring 6 will raise its system requirements to JDK 9+ in any case, so a focus on proper module descriptors would go along nicely. |
Paul Bakker commented Concrats on the first Spring 5 release. Recently the sentiment about automatic modules and releasing modules that use automatic modules seems to have changed a little. Would it be worth looking into writing module-infos for Spring 5 as well? |
Juergen Hoeller commented The sentiment around automatic modules has certainly hardened. At least we have a mechanism for defining automatic module names without full descriptors now. However, we are still stuck with respect to explicit module-info descriptors: We cannot ship dependency-declaring descriptors of our own before the maintainers of all of our third-party dependencies agree on module names. We are at the end of the open source consumption chain, so we cannot be first movers in that respect. The "Automatic-Module-Name" manifest entry might be an easy enough technical way out for the naming problem... but even that has to be adopted broadly first. Frankly, I don't see a well-established module namespace in the open source ecosystem so quickly. I still don't expect all of our dependencies to arrive there before 2019. At the Java EE level, the umbrella expert group has already clarified that they are not going to support official module name declarations for their APIs before EE 9, silencing attempts to do this e.g. for JPA. And with yesterday's rejection of the current Jigsaw proposal in the EC and the propaganda around it, it's even less likely that there will be broad early adoption. Even revisiting this with Spring 6, we might still find a rather incomplete ecosystem then. So for the time being, all we can sensibly do is to focus on usage as automatic modules. I recently re-tested against JDK 9 build 167 and was quite pleased with the outcome, since even transitive resolution of automatic module dependencies works seamlessly now. For Spring applications, the experience is quite alright that way: e.g. |
Paul Bakker commented I just downloaded Spring Core RC2 and noticed that there is no Automatic-Module-Name set in the manifest. It's probably a good idea to add that for this release (for all modules), until a future release adds a module-info.java. |
Juergen Hoeller commented Indeed, and we intend to do so as of 5.0 RC3, tracked through (the slightly repurposed) ticket #18289. However, I'm still in favor of For us, quite a few of our jars do not have a single root package but rather aggregate several packages, so a reverse domain name would arguably suggest the false promise of a single contained package of the same name. A distinct module name space just like in the JDK arguably represents our arrangement much better, using the power of modules as fine-tuned aggregates of related functionality and not just as rather dumb units of deployment per root package. FWIW, several Java EE API jars intend to adopt the JDK naming style as well. |
Philippe Marschall commented
AFAIK everything under the JCP should do so, I would expect every Java EE API to follow this style. |
Juergen Hoeller commented I've added a few further notes to applicable places in the reference documentation, with respect to component scanning as well as resource pattern matching. Since such arrangements effectively work fine on Jigsaw as well, with largely the same limitations as in portable classpath setups (in particular avoiding searches in jar file roots, putting resources into a directory instead), those notes are not too extensive and nicely fold into the general storyline of those chapters. I've also added a note on |
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.
This results in the following error:
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
The text was updated successfully, but these errors were encountered: