Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ec13a3f

Browse filesBrowse files
committed
Backported clarifications for SchedulerFactoryBean and cache annotations
See gh-27709 See gh-27726
1 parent 842f5b3 commit ec13a3f
Copy full SHA for ec13a3f

File tree

Expand file treeCollapse file tree

3 files changed

+52
-50
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+52
-50
lines changed

‎spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java

Copy file name to clipboardExpand all lines: spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,6 +58,8 @@
5858
* @since 1.1
5959
* @see SchedulerFactoryBean#setDataSource
6060
* @see SchedulerFactoryBean#setNonTransactionalDataSource
61+
* @see SchedulerFactoryBean#getConfigTimeDataSource()
62+
* @see SchedulerFactoryBean#getConfigTimeNonTransactionalDataSource()
6163
* @see org.springframework.jdbc.datasource.DataSourceUtils#doGetConnection
6264
* @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
6365
*/

‎spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java

Copy file name to clipboardExpand all lines: spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -313,6 +313,7 @@ public void setTaskExecutor(Executor taskExecutor) {
313313
* If set, this will override corresponding settings in Quartz properties.
314314
* <p>Note: If this is set, the Quartz settings should not define
315315
* a job store "dataSource" to avoid meaningless double configuration.
316+
* Also, do not define a "org.quartz.jobStore.class" property at all.
316317
* <p>A Spring-specific subclass of Quartz' JobStoreCMT will be used.
317318
* It is therefore strongly recommended to perform all operations on
318319
* the Scheduler within Spring-managed (or plain JTA) transactions.

‎src/docs/asciidoc/integration.adoc

Copy file name to clipboardExpand all lines: src/docs/asciidoc/integration.adoc
+47-48Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6615,7 +6615,6 @@ has it applied automatically:
66156615
protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
66166616
// do the actual work
66176617
}
6618-
66196618
}
66206619
----
66216620

@@ -6740,11 +6739,17 @@ seconds and one running every morning at 6 AM. To finalize everything, we need t
67406739
</bean>
67416740
----
67426741

6743-
More properties are available for the `SchedulerFactoryBean`, such as the calendars
6744-
used by the job details, properties to customize Quartz with, and others. See the
6745-
{api-spring-framework}/scheduling/quartz/SchedulerFactoryBean.html[`SchedulerFactoryBean`]
6742+
More properties are available for the `SchedulerFactoryBean`, such as the calendars used by the
6743+
job details, properties to customize Quartz with, and a Spring-provided JDBC DataSource. See
6744+
the {api-spring-framework}/scheduling/quartz/SchedulerFactoryBean.html[`SchedulerFactoryBean`]
67466745
javadoc for more information.
67476746

6747+
NOTE: `SchedulerFactoryBean` also recognizes a `quartz.properties` file in the classpath,
6748+
based on Quartz property keys, as with regular Quartz configuration. Please note that many
6749+
`SchedulerFactoryBean` settings interact with common Quartz settings in the properties file;
6750+
it is therefore not recommended to specify values at both levels. For example, do not set
6751+
an "org.quartz.jobStore.class" property if you mean to rely on a Spring-provided DataSource.
6752+
67486753

67496754

67506755

@@ -6756,8 +6761,8 @@ an existing Spring application. Similar to the <<data-access.adoc#transaction, t
67566761
support, the caching abstraction allows consistent use of various caching solutions with
67576762
minimal impact on the code.
67586763

6759-
As from Spring 4.1, the cache abstraction has been significantly extended with the
6760-
support of <<cache-jsr-107,JSR-107 annotations>> and more customization options.
6764+
In Spring Framework 4.1, the cache abstraction was significantly extended with support
6765+
for <<cache-jsr-107,JSR-107 annotations>> and more customization options.
67616766

67626767

67636768

@@ -6815,15 +6820,16 @@ compliant caches (such as Ehcache 3.x). See <<cache-plug>> for more information
68156820
plugging in other cache stores and providers.
68166821

68176822
IMPORTANT: The caching abstraction has no special handling for multi-threaded and
6818-
multi-process environments, as such features are handled by the cache implementation. .
6823+
multi-process environments, as such features are handled by the cache implementation.
68196824

68206825
If you have a multi-process environment (that is, an application deployed on several nodes),
68216826
you need to configure your cache provider accordingly. Depending on your use cases, a copy
68226827
of the same data on several nodes can be enough. However, if you change the data during
68236828
the course of the application, you may need to enable other propagation mechanisms.
68246829

6825-
Caching a particular item is a direct equivalent of the typical get-if-not-found-then-
6826-
proceed-and-put-eventually code blocks found with programmatic cache interaction.
6830+
Caching a particular item is a direct equivalent of the typical
6831+
get-if-not-found-then-proceed-and-put-eventually code blocks
6832+
found with programmatic cache interaction.
68276833
No locks are applied, and several threads may try to load the same item concurrently.
68286834
The same applies to eviction. If several threads are trying to update or evict data
68296835
concurrently, you may use stale data. Certain cache providers offer advanced features
@@ -6875,7 +6881,7 @@ method -- if at least one cache is hit, the associated value is returned.
68756881
NOTE: All the other caches that do not contain the value are also updated, even though
68766882
the cached method was not actually invoked.
68776883

6878-
The following example uses `@Cacheable` on the `findBook` method:
6884+
The following example uses `@Cacheable` on the `findBook` method with multiple caches:
68796885

68806886
[source,java,indent=0]
68816887
[subs="verbatim,quotes"]
@@ -7028,7 +7034,7 @@ regardless of the content of the annotation.
70287034
70297035
Similarly to `key` and `keyGenerator`, the `cacheManager` and `cacheResolver`
70307036
parameters are mutually exclusive, and an operation specifying both
7031-
results in an exception. as a custom `CacheManager` is ignored by the
7037+
results in an exception, as a custom `CacheManager` is ignored by the
70327038
`CacheResolver` implementation. This is probably not what you expect.
70337039
====
70347040

@@ -7053,7 +7059,6 @@ is updated in the cache. The following example shows how to use the `sync` attri
70537059
----
70547060
<1> Using the `sync` attribute.
70557061

7056-
70577062
NOTE: This is an optional feature, and your favorite cache library may not support it.
70587063
All `CacheManager` implementations provided by the core framework support it. See the
70597064
documentation of your cache provider for more details.
@@ -7092,9 +7097,11 @@ want to cache paperback books, as the following example does:
70927097
<1> Using the `unless` attribute to block hardbacks.
70937098

70947099

7095-
The cache abstraction supports `java.util.Optional`, using its content as the cached value
7096-
only if it is present. `#result` always refers to the business entity and never a
7097-
supported wrapper, so the previous example can be rewritten as follows:
7100+
The cache abstraction supports `java.util.Optional` return types. If an `Optional` value
7101+
is _present_, it will be stored in the associated cache. If an `Optional` value is not
7102+
present, `null` will be stored in the associated cache. `#result` always refers to the
7103+
business entity and never a supported wrapper, so the previous example can be rewritten
7104+
as follows:
70987105

70997106
[source,java,indent=0]
71007107
[subs="verbatim,quotes"]
@@ -7103,8 +7110,8 @@ supported wrapper, so the previous example can be rewritten as follows:
71037110
public Optional<Book> findBook(String name)
71047111
----
71057112

7106-
Note that `result` still refers to `Book` and not `Optional`. As it might be `null`, we
7107-
should use the safe navigation operator.
7113+
Note that `#result` still refers to `Book` and not `Optional<Book>`. Since it might be
7114+
`null`, we use SpEL's <<core.adoc#expressions-operator-safe-navigation, safe navigation operator>>.
71087115

71097116
[[cache-spel-context]]
71107117
===== Available Caching SpEL Evaluation Context
@@ -7214,7 +7221,6 @@ all entries from the `books` cache:
72147221
----
72157222
<1> Using the `allEntries` attribute to evict all entries from the cache.
72167223

7217-
72187224
This option comes in handy when an entire cache region needs to be cleared out.
72197225
Rather than evicting each entry (which would take a long time, since it is inefficient),
72207226
all the entries are removed in one operation, as the preceding example shows.
@@ -7275,7 +7281,6 @@ comes into play. The following examples uses `@CacheConfig` to set the name of t
72757281
----
72767282
<1> Using `@CacheConfig` to set the name of the cache.
72777283

7278-
72797284
`@CacheConfig` is a class-level annotation that allows sharing the cache names,
72807285
the custom `KeyGenerator`, the custom `CacheManager`, and the custom `CacheResolver`.
72817286
Placing this annotation on the class does not turn on any caching operation.
@@ -7418,13 +7423,11 @@ if you need to annotate non-public methods, as it changes the bytecode itself.
74187423
****
74197424

74207425
TIP: Spring recommends that you only annotate concrete classes (and methods of concrete
7421-
classes) with the `@Cache{asterisk}` annotation, as opposed to annotating interfaces.
7422-
You certainly can place the `@Cache{asterisk}` annotation on an interface (or an interface
7423-
method), but this works only as you would expect it to if you use interface-based proxies.
7424-
The fact that Java annotations are not inherited from interfaces means that, if you use
7425-
class-based proxies (`proxy-target-class="true"`) or the weaving-based aspect
7426-
(`mode="aspectj"`), the caching settings are not recognized by the proxying and weaving
7427-
infrastructure, and the object is not wrapped in a caching proxy.
7426+
classes) with the `@Cache{asterisk}` annotations, as opposed to annotating interfaces.
7427+
You certainly can place an `@Cache{asterisk}` annotation on an interface (or an interface
7428+
method), but this works only if you use the proxy mode (`mode="proxy"`). If you use the
7429+
weaving-based aspect (`mode="aspectj"`), the caching settings are not recognized on
7430+
interface-level declarations by the weaving infrastructure.
74287431

74297432
NOTE: In proxy mode (the default), only external method calls coming in through the
74307433
proxy are intercepted. This means that self-invocation (in effect, a method within the
@@ -7499,7 +7502,7 @@ up its declaration at runtime and understands its meaning. Note that, as mention
74997502
=== JCache (JSR-107) Annotations
75007503

75017504
Since version 4.1, Spring's caching abstraction fully supports the JCache standard
7502-
annotations: `@CacheResult`, `@CachePut`, `@CacheRemove`, and `@CacheRemoveAll`
7505+
(JSR-107) annotations: `@CacheResult`, `@CachePut`, `@CacheRemove`, and `@CacheRemoveAll`
75037506
as well as the `@CacheDefaults`, `@CacheKey`, and `@CacheValue` companions.
75047507
You can use these annotations even without migrating your cache store to JSR-107.
75057508
The internal implementation uses Spring's caching abstraction and provides default
@@ -7513,8 +7516,8 @@ you can switch to these standard annotations without changing your cache storage
75137516
==== Feature Summary
75147517

75157518
For those who are familiar with Spring's caching annotations, the following table
7516-
describes the main differences between the Spring annotations and the JSR-107
7517-
counterpart:
7519+
describes the main differences between the Spring annotations and their JSR-107
7520+
counterparts:
75187521

75197522
.Spring vs. JSR-107 caching annotations
75207523
[cols="1,1,3"]
@@ -7565,7 +7568,6 @@ to customize the factory for each cache operation, as the following example show
75657568
----
75667569
<1> Customizing the factory for this operation.
75677570

7568-
75697571
NOTE: For all referenced classes, Spring tries to locate a bean with the given type.
75707572
If more than one match exists, a new instance is created and can use the regular
75717573
bean lifecycle callbacks, such as dependency injection.
@@ -7609,16 +7611,15 @@ invoking the method again:
76097611

76107612
==== Enabling JSR-107 Support
76117613

7612-
You need do nothing specific to enable the JSR-107 support alongside Spring's
7613-
declarative annotation support. Both `@EnableCaching` and the
7614-
`cache:annotation-driven` element automatically enable the JCache support
7615-
if both the JSR-107 API and the `spring-context-support` module are present
7616-
in the classpath.
7614+
You do not need to do anything specific to enable the JSR-107 support alongside Spring's
7615+
declarative annotation support. Both `@EnableCaching` and the `cache:annotation-driven`
7616+
XML element automatically enable the JCache support if both the JSR-107 API and the
7617+
`spring-context-support` module are present in the classpath.
76177618

7618-
NOTE: Depending on your use case, the choice is basically yours. You can even
7619-
mix and match services by using the JSR-107 API on some and using Spring's own
7620-
annotations on others. However, if these services impact the same caches,
7621-
you should use a consistent and identical key generation implementation.
7619+
NOTE: Depending on your use case, the choice is basically yours. You can even mix and
7620+
match services by using the JSR-107 API on some and using Spring's own annotations on
7621+
others. However, if these services impact the same caches, you should use a consistent
7622+
and identical key generation implementation.
76227623

76237624

76247625

@@ -7848,15 +7849,13 @@ invoked every time.
78487849
=== Plugging-in Different Back-end Caches
78497850

78507851
Clearly, there are plenty of caching products out there that you can use as a backing
7851-
store. To plug them in, you need to provide a `CacheManager` and a `Cache` implementation,
7852-
since, unfortunately, there is no available standard that we can use instead.
7853-
This may sound harder than it is, since, in practice, the classes tend to be simple
7854-
https://en.wikipedia.org/wiki/Adapter_pattern[adapters] that map the caching abstraction
7855-
framework on top of the storage API, as the `ehcache` classes do. Most `CacheManager`
7856-
classes can use the classes in the `org.springframework.cache.support` package
7857-
(such as `AbstractCacheManager` which takes care of the boiler-plate code,
7858-
leaving only the actual mapping to be completed). We hope that, in time, the libraries
7859-
that provide integration with Spring can fill in this small configuration gap.
7852+
store. For those that do not support JSR-107 you need to provide a `CacheManager` and a
7853+
`Cache` implementation. This may sound harder than it is, since, in practice, the classes
7854+
tend to be simple https://en.wikipedia.org/wiki/Adapter_pattern[adapters] that map the
7855+
caching abstraction framework on top of the storage API, as the `ehcache` classes do.
7856+
Most `CacheManager` classes can use the classes in the
7857+
`org.springframework.cache.support` package (such as `AbstractCacheManager` which takes
7858+
care of the boiler-plate code, leaving only the actual mapping to be completed).
78607859

78617860

78627861

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.