Skip to content

Commit 550f05c

Browse files
committed
Merge branch '6.0.x'
# Conflicts: # spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
2 parents 5bcbcb3 + 659500b commit 550f05c

File tree

5 files changed

+100
-58
lines changed

5 files changed

+100
-58
lines changed

framework-docs/modules/ROOT/pages/integration/scheduling.adoc

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ The Spring Framework provides abstractions for the asynchronous execution and sc
55
tasks with the `TaskExecutor` and `TaskScheduler` interfaces, respectively. Spring also
66
features implementations of those interfaces that support thread pools or delegation to
77
CommonJ within an application server environment. Ultimately, the use of these
8-
implementations behind the common interfaces abstracts away the differences between Java
9-
SE 5, Java SE 6, and Jakarta EE environments.
8+
implementations behind the common interfaces abstracts away the differences between
9+
Java SE and Jakarta EE environments.
1010

11-
Spring also features integration classes to support scheduling with the `Timer`
12-
(part of the JDK since 1.3) and the https://www.quartz-scheduler.org/[Quartz Scheduler].
13-
You can set up both of those schedulers by using a `FactoryBean` with optional references to
14-
`Timer` or `Trigger` instances, respectively. Furthermore, a convenience class for both
15-
the Quartz Scheduler and the `Timer` is available that lets you invoke a method of
16-
an existing target object (analogous to the normal `MethodInvokingFactoryBean`
17-
operation).
11+
Spring also features integration classes to support scheduling with the
12+
https://www.quartz-scheduler.org/[Quartz Scheduler].
1813

1914

2015

@@ -271,8 +266,8 @@ execution.
271266
[[scheduling-enable-annotation-support]]
272267
=== Enable Scheduling Annotations
273268

274-
To enable support for `@Scheduled` and `@Async` annotations, you can add `@EnableScheduling` and
275-
`@EnableAsync` to one of your `@Configuration` classes, as the following example shows:
269+
To enable support for `@Scheduled` and `@Async` annotations, you can add `@EnableScheduling`
270+
and `@EnableAsync` to one of your `@Configuration` classes, as the following example shows:
276271

277272
[source,java,indent=0,subs="verbatim,quotes"]
278273
----
@@ -552,8 +547,8 @@ to a method that returns `void`, as the following example shows:
552547

553548
Unlike the methods annotated with the `@Scheduled` annotation, these methods can expect
554549
arguments, because they are invoked in the "`normal`" way by callers at runtime rather
555-
than from a scheduled task being managed by the container. For example, the following code is
556-
a legitimate application of the `@Async` annotation:
550+
than from a scheduled task being managed by the container. For example, the following
551+
code is a legitimate application of the `@Async` annotation:
557552

558553
[source,java,indent=0,subs="verbatim,quotes"]
559554
----
@@ -577,15 +572,15 @@ that returns a value:
577572
}
578573
----
579574

580-
TIP: `@Async` methods may not only declare a regular `java.util.concurrent.Future` return type
581-
but also Spring's `org.springframework.util.concurrent.ListenableFuture` or, as of Spring
582-
4.2, JDK 8's `java.util.concurrent.CompletableFuture`, for richer interaction with the
583-
asynchronous task and for immediate composition with further processing steps.
575+
TIP: `@Async` methods may not only declare a regular `java.util.concurrent.Future` return
576+
type but also Spring's `org.springframework.util.concurrent.ListenableFuture` or, as of
577+
Spring 4.2, JDK 8's `java.util.concurrent.CompletableFuture`, for richer interaction with
578+
the asynchronous task and for immediate composition with further processing steps.
584579

585-
You can not use `@Async` in conjunction with lifecycle callbacks such as
586-
`@PostConstruct`. To asynchronously initialize Spring beans, you currently have to use
587-
a separate initializing Spring bean that then invokes the `@Async` annotated method on the
588-
target, as the following example shows:
580+
You can not use `@Async` in conjunction with lifecycle callbacks such as `@PostConstruct`.
581+
To asynchronously initialize Spring beans, you currently have to use a separate
582+
initializing Spring bean that then invokes the `@Async` annotated method on the target,
583+
as the following example shows:
589584

590585
[source,java,indent=0,subs="verbatim,quotes"]
591586
----
@@ -639,8 +634,8 @@ used when executing a given method. The following example shows how to do so:
639634
----
640635

641636
In this case, `"otherExecutor"` can be the name of any `Executor` bean in the Spring
642-
container, or it may be the name of a qualifier associated with any `Executor` (for example, as
643-
specified with the `<qualifier>` element or Spring's `@Qualifier` annotation).
637+
container, or it may be the name of a qualifier associated with any `Executor` (for example,
638+
as specified with the `<qualifier>` element or Spring's `@Qualifier` annotation).
644639

645640

646641
[[scheduling-annotation-support-exception]]
@@ -808,14 +803,15 @@ invoked on that object. The following listing shows a simple example:
808803
----
809804

810805
The scheduler is referenced by the outer element, and each individual
811-
task includes the configuration of its trigger metadata. In the preceding example, that
812-
metadata defines a periodic trigger with a fixed delay indicating the number of
806+
task includes the configuration of its trigger metadata. In the preceding example,
807+
that metadata defines a periodic trigger with a fixed delay indicating the number of
813808
milliseconds to wait after each task execution has completed. Another option is
814809
`fixed-rate`, indicating how often the method should be run regardless of how long
815-
any previous execution takes. Additionally, for both `fixed-delay` and `fixed-rate` tasks, you can specify an
816-
'initial-delay' parameter, indicating the number of milliseconds to wait
817-
before the first execution of the method. For more control, you can instead provide a `cron` attribute
818-
to provide a xref:integration/scheduling.adoc#scheduling-cron-expression[cron expression].
810+
any previous execution takes. Additionally, for both `fixed-delay` and `fixed-rate`
811+
tasks, you can specify an 'initial-delay' parameter, indicating the number of
812+
milliseconds to wait before the first execution of the method. For more control,
813+
you can instead provide a `cron` attribute to provide a
814+
xref:integration/scheduling.adoc#scheduling-cron-expression[cron expression].
819815
The following example shows these other options:
820816

821817
[source,xml,indent=0]
@@ -838,9 +834,8 @@ The following example shows these other options:
838834
All Spring cron expressions have to conform to the same format, whether you are using them in
839835
xref:integration/scheduling.adoc#scheduling-annotation-support-scheduled[`@Scheduled` annotations],
840836
xref:integration/scheduling.adoc#scheduling-task-namespace-scheduled-tasks[`task:scheduled-tasks` elements],
841-
or someplace else.
842-
A well-formed cron expression, such as `* * * * * *`, consists of six space-separated time and date
843-
fields, each with its own range of valid values:
837+
or someplace else. A well-formed cron expression, such as `* * * * * *`, consists of six
838+
space-separated time and date fields, each with its own range of valid values:
844839

845840

846841
....
@@ -905,9 +900,10 @@ Here are some examples:
905900
[[macros]]
906901
=== Macros
907902

908-
Expressions such as `0 0 * * * *` are hard for humans to parse and are, therefore, hard to fix in case of bugs.
909-
To improve readability, Spring supports the following macros, which represent commonly used sequences.
910-
You can use these macros instead of the six-digit value, thus: `@Scheduled(cron = "@hourly")`.
903+
Expressions such as `0 0 * * * *` are hard for humans to parse and are, therefore,
904+
hard to fix in case of bugs. To improve readability, Spring supports the following
905+
macros, which represent commonly used sequences. You can use these macros instead
906+
of the six-digit value, thus: `@Scheduled(cron = "@hourly")`.
911907

912908
|===
913909
|Macro | Meaning
@@ -924,18 +920,18 @@ You can use these macros instead of the six-digit value, thus: `@Scheduled(cron
924920
[[scheduling-quartz]]
925921
== Using the Quartz Scheduler
926922

927-
Quartz uses `Trigger`, `Job`, and `JobDetail` objects to realize scheduling of all kinds
928-
of jobs. For the basic concepts behind Quartz, see the
923+
Quartz uses `Trigger`, `Job`, and `JobDetail` objects to realize scheduling of all
924+
kinds of jobs. For the basic concepts behind Quartz, see the
929925
https://www.quartz-scheduler.org/[Quartz Web site]. For convenience purposes, Spring
930926
offers a couple of classes that simplify using Quartz within Spring-based applications.
931927

932928

933929
[[scheduling-quartz-jobdetail]]
934930
=== Using the `JobDetailFactoryBean`
935931

936-
Quartz `JobDetail` objects contain all the information needed to run a job. Spring provides a
937-
`JobDetailFactoryBean`, which provides bean-style properties for XML configuration purposes.
938-
Consider the following example:
932+
Quartz `JobDetail` objects contain all the information needed to run a job. Spring
933+
provides a `JobDetailFactoryBean`, which provides bean-style properties for XML
934+
configuration purposes. Consider the following example:
939935

940936
[source,xml,indent=0,subs="verbatim,quotes"]
941937
----
@@ -952,9 +948,9 @@ Consider the following example:
952948
The job detail configuration has all the information it needs to run the job (`ExampleJob`).
953949
The timeout is specified in the job data map. The job data map is available through the
954950
`JobExecutionContext` (passed to you at execution time), but the `JobDetail` also gets
955-
its properties from the job data mapped to properties of the job instance. So, in the following example,
956-
the `ExampleJob` contains a bean property named `timeout`, and the `JobDetail`
957-
has it applied automatically:
951+
its properties from the job data mapped to properties of the job instance. So, in the
952+
following example, the `ExampleJob` contains a bean property named `timeout`, and the
953+
`JobDetail` has it applied automatically:
958954

959955
[source,java,indent=0,subs="verbatim,quotes",chomp="-packages"]
960956
----
@@ -1047,8 +1043,8 @@ NOTE: By default, jobs will run in a concurrent fashion.
10471043
[[scheduling-quartz-cron]]
10481044
=== Wiring up Jobs by Using Triggers and `SchedulerFactoryBean`
10491045

1050-
We have created job details and jobs. We have also reviewed the convenience bean that lets
1051-
you invoke a method on a specific object. Of course, we still need to schedule the
1046+
We have created job details and jobs. We have also reviewed the convenience bean that
1047+
lets you invoke a method on a specific object. Of course, we still need to schedule the
10521048
jobs themselves. This is done by using triggers and a `SchedulerFactoryBean`. Several
10531049
triggers are available within Quartz, and Spring offers two Quartz `FactoryBean`
10541050
implementations with convenient defaults: `CronTriggerFactoryBean` and
@@ -1079,9 +1075,9 @@ The following listing uses both a `SimpleTriggerFactoryBean` and a `CronTriggerF
10791075
</bean>
10801076
----
10811077

1082-
The preceding example sets up two triggers, one running every 50 seconds with a starting delay of 10
1083-
seconds and one running every morning at 6 AM. To finalize everything, we need to set up the
1084-
`SchedulerFactoryBean`, as the following example shows:
1078+
The preceding example sets up two triggers, one running every 50 seconds with a starting
1079+
delay of 10 seconds and one running every morning at 6 AM. To finalize everything,
1080+
we need to set up the `SchedulerFactoryBean`, as the following example shows:
10851081

10861082
[source,xml,indent=0,subs="verbatim,quotes"]
10871083
----

spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ private static Duration toDuration(long value, TimeUnit timeUnit) {
554554
}
555555
catch (Exception ex) {
556556
throw new IllegalArgumentException(
557-
"Unsupported unit " + timeUnit + " for value \"" + value + "\": " + ex.getMessage(), ex);
557+
"Unsupported unit " + timeUnit + " for value \"" + value + "\": " + ex.getMessage());
558558
}
559559
}
560560

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.core.io.support;
1818

1919
import java.io.File;
20+
import java.io.FileNotFoundException;
2021
import java.io.IOException;
2122
import java.io.UncheckedIOException;
2223
import java.lang.module.ModuleFinder;
@@ -786,10 +787,26 @@ protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource
786787
// Fallback via Resource.getFile() below
787788
}
788789
}
790+
789791
if (rootPath == null) {
790792
// Resource.getFile() resolution as a fallback -
791793
// for custom URI formats and custom Resource implementations
792-
rootPath = Path.of(rootDirResource.getFile().getAbsolutePath());
794+
try {
795+
rootPath = Path.of(rootDirResource.getFile().getAbsolutePath());
796+
}
797+
catch (FileNotFoundException ex) {
798+
if (logger.isDebugEnabled()) {
799+
logger.debug("Cannot search for matching files underneath " + rootDirResource +
800+
" in the file system: " + ex.getMessage());
801+
}
802+
return result;
803+
}
804+
catch (Exception ex) {
805+
if (logger.isInfoEnabled()) {
806+
logger.info("Failed to resolve " + rootDirResource + " in the file system: " + ex);
807+
}
808+
return result;
809+
}
793810
}
794811

795812
if (!Files.exists(rootPath)) {

0 commit comments

Comments
 (0)