Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
3b0f00dc
Commit
3b0f00dc
authored
Oct 09, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document how to enable Hibernate 2nd level cache with JCache
Closes gh-14734
parent
acba77ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
0 deletions
+70
-0
pom.xml
spring-boot-project/spring-boot-docs/pom.xml
+5
-0
howto.adoc
...oot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
+21
-0
HibernateSecondLevelCacheExample.java
...ework/boot/docs/jpa/HibernateSecondLevelCacheExample.java
+44
-0
No files found.
spring-boot-project/spring-boot-docs/pom.xml
View file @
3b0f00dc
...
@@ -577,6 +577,11 @@
...
@@ -577,6 +577,11 @@
<artifactId>
hibernate-core
</artifactId>
<artifactId>
hibernate-core
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-jcache
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<dependency>
<groupId>
org.hibernate.validator
</groupId>
<groupId>
org.hibernate.validator
</groupId>
<artifactId>
hibernate-validator
</artifactId>
<artifactId>
hibernate-validator
</artifactId>
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
View file @
3b0f00dc
...
@@ -2003,6 +2003,27 @@ for more details.
...
@@ -2003,6 +2003,27 @@ for more details.
[[howto-configure-hibernate-second-level-caching]]
=== Configure Hibernate Second-Level Caching
Hibernate {hibernate-documentation}#caching[second-level cache] can be configured for a
range of cache providers. Rather than configuring Hibernate to lookup the cache provider
again, it is better to provide the one that is available in the context whenever possible.
If you're using JCache, this is pretty easy. First, make sure that
`org.hibernate:hibernate-jcache` is available on the classpath. Then, add a
`HibernatePropertiesCustomizer` bean as shown in the following example:
[source,java,indent=0]
----
include::{code-examples}/jpa/HibernateSecondLevelCacheExample.java[tag=configuration]
----
This customizer will configure Hibernate to use the same `CacheManager` as the one that
the application uses. It is also possible to use separate `CacheManager` instances, refer
to {hibernate-documentation}#caching-provider-jcache[the Hibernate user guide].
[[howto-use-dependency-injection-hibernate-components]]
[[howto-use-dependency-injection-hibernate-components]]
=== Use Dependency Injection in Hibernate Components
=== Use Dependency Injection in Hibernate Components
By default, Spring Boot registers a `BeanContainer` implementation that uses the
By default, Spring Boot registers a `BeanContainer` implementation that uses the
...
...
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/jpa/HibernateSecondLevelCacheExample.java
0 → 100644
View file @
3b0f00dc
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
docs
.
jpa
;
import
org.hibernate.cache.jcache.ConfigSettings
;
import
org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer
;
import
org.springframework.cache.jcache.JCacheCacheManager
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* Example configuration of using JCache and Hibernate to enable second level caching.
*
* @author Stephane Nicoll
*/
// tag::configuration[]
@Configuration
public
class
HibernateSecondLevelCacheExample
{
@Bean
public
HibernatePropertiesCustomizer
hibernateSecondLevelCacheCustomizer
(
JCacheCacheManager
cacheManager
)
{
return
(
properties
)
->
properties
.
put
(
ConfigSettings
.
CACHE_MANAGER
,
cacheManager
.
getCacheManager
());
}
}
// end::configuration[]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment