Skip to content

Commit 6ef7dd4

Browse files
committed
Notes on classpath scanning and exports vs opens with Jigsaw
Issue: SPR-14579
1 parent dc32991 commit 6ef7dd4

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/docs/asciidoc/core/core-beans.adoc

+8-2
Original file line numberDiff line numberDiff line change
@@ -5347,7 +5347,7 @@ comma/semicolon/space-separated list that includes the parent package of each cl
53475347

53485348
[NOTE]
53495349
====
5350-
for concision, the above may have used the `value` attribute of the
5350+
For concision, the above may have used the `value` attribute of the
53515351
annotation, i.e. `@ComponentScan("org.example")`
53525352
====
53535353

@@ -5385,6 +5385,12 @@ activate the files-only switch of the JAR task. Also, classpath directories may
53855385
get exposed based on security policies in some environments, e.g. standalone apps on
53865386
JDK 1.7.0_45 and higher (which requires 'Trusted-Library' setup in your manifests; see
53875387
http://stackoverflow.com/questions/19394570/java-jre-7u45-breaks-classloader-getresources).
5388+
5389+
On JDK 9's module path (Jigsaw), Spring's classpath scanning generally works as expected.
5390+
However, please make sure that your component classes are exported in your `module-info`
5391+
descriptors; if you expect Spring to invoke non-public members of your classes, make
5392+
sure that they are 'opened' (i.e. using an `opens` declaration instead of an `exports`
5393+
declaration in your `module-info` descriptor).
53885394
====
53895395

53905396
Furthermore, the `AutowiredAnnotationBeanPostProcessor` and
@@ -5396,7 +5402,7 @@ wired together - all without any bean configuration metadata provided in XML.
53965402
====
53975403
You can disable the registration of `AutowiredAnnotationBeanPostProcessor` and
53985404
`CommonAnnotationBeanPostProcessor` by including the __annotation-config__ attribute
5399-
with a value of false.
5405+
with a value of `false`.
54005406
====
54015407

54025408

src/docs/asciidoc/core/core-resources.adoc

+21-3
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,28 @@ strategy described above is used for the wildcard subpath.
568568
Please note that `classpath*:` when combined with Ant-style patterns will only work
569569
reliably with at least one root directory before the pattern starts, unless the actual
570570
target files reside in the file system. This means that a pattern like
571-
`classpath*:*.xml` will not retrieve files from the root of jar files but rather only
572-
from the root of expanded directories. This originates from a limitation in the JDK's
571+
`classpath*:*.xml` might not retrieve files from the root of jar files but rather only
572+
from the root of expanded directories.
573+
574+
Spring's ability to retrieve classpath entries originates from the JDK's
573575
`ClassLoader.getResources()` method which only returns file system locations for a
574-
passed-in empty string (indicating potential roots to search).
576+
passed-in empty string (indicating potential roots to search). Spring evaluates
577+
`URLClassLoader` runtime configuration and the "java.class.path" manifest in jar files
578+
as well but this is not guaranteed to lead to portable behavior.
579+
580+
[NOTE]
581+
====
582+
The scanning of classpath packages requires the presence of corresponding directory
583+
entries in the classpath. When you build JARs with Ant, make sure that you do __not__
584+
activate the files-only switch of the JAR task. Also, classpath directories may not
585+
get exposed based on security policies in some environments, e.g. standalone apps on
586+
JDK 1.7.0_45 and higher (which requires 'Trusted-Library' setup in your manifests; see
587+
http://stackoverflow.com/questions/19394570/java-jre-7u45-breaks-classloader-getresources).
588+
589+
On JDK 9's module path (Jigsaw), Spring's classpath scanning generally works as expected.
590+
Putting resources into a dedicated directory is highly recommendable here as well,
591+
avoiding the aforementioned portability problems with searching the jar file root level.
592+
====
575593

576594
Ant-style patterns with `classpath:` resources are not guaranteed to find matching
577595
resources if the root package to search is available in multiple class path locations.

0 commit comments

Comments
 (0)