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
6505e03c
Commit
6505e03c
authored
Jun 02, 2021
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add auto-configuration for Spring Data Envers"
See gh-22610
parent
91da8c9f
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
130 additions
and
19 deletions
+130
-19
build.gradle
spring-boot-project/spring-boot-autoconfigure/build.gradle
+1
-1
EnversRevisionRepositoriesRegistrar.java
...nfigure/data/jpa/EnversRevisionRepositoriesRegistrar.java
+1
-1
JpaRepositoriesAutoConfiguration.java
...oconfigure/data/jpa/JpaRepositoriesAutoConfiguration.java
+18
-10
AbstractJpaRepositoriesAutoConfigurationTests.java
...ta/jpa/AbstractJpaRepositoriesAutoConfigurationTests.java
+1
-1
EnversRevisionRepositoriesAutoConfigurationTests.java
...jpa/EnversRevisionRepositoriesAutoConfigurationTests.java
+1
-1
JpaRepositoriesAutoConfigurationTests.java
...igure/data/jpa/JpaRepositoriesAutoConfigurationTests.java
+1
-1
City.java
...pringframework/boot/autoconfigure/data/jpa/city/City.java
+1
-1
CityRepository.java
...work/boot/autoconfigure/data/jpa/city/CityRepository.java
+1
-1
Country.java
...ramework/boot/autoconfigure/data/jpa/country/Country.java
+1
-1
CountryRepository.java
...oot/autoconfigure/data/jpa/country/CountryRepository.java
+1
-1
build.gradle
spring-boot-project/spring-boot-docs/build.gradle
+2
-0
attributes.adoc
...roject/spring-boot-docs/src/docs/asciidoc/attributes.adoc
+2
-0
sql.adoc
...ject/spring-boot-docs/src/docs/asciidoc/features/sql.adoc
+15
-0
Country.java
.../features/sql/jpaandspringdata/entityclasses/Country.java
+55
-0
CountryRepository.java
.../sql/jpaandspringdata/repositories/CountryRepository.java
+29
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/build.gradle
View file @
6505e03c
...
...
@@ -112,8 +112,8 @@ dependencies {
optional
(
"org.springframework:spring-webmvc"
)
optional
(
"org.springframework.batch:spring-batch-core"
)
optional
(
"org.springframework.data:spring-data-couchbase"
)
optional
(
"org.springframework.data:spring-data-jpa"
)
optional
(
"org.springframework.data:spring-data-envers"
)
optional
(
"org.springframework.data:spring-data-jpa"
)
optional
(
"org.springframework.data:spring-data-rest-webmvc"
)
optional
(
"org.springframework.data:spring-data-cassandra"
)
optional
(
"org.springframework.data:spring-data-elasticsearch"
)
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jpa/EnversRevisionRepositoriesRegistrar.java
View file @
6505e03c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfiguration.java
View file @
6505e03c
...
...
@@ -26,8 +26,8 @@ import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration.JpaRepositoriesImportSelector
;
import
org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilderCustomizer
;
import
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
;
import
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration
;
...
...
@@ -35,7 +35,9 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.ImportSelector
;
import
org.springframework.core.task.AsyncTaskExecutor
;
import
org.springframework.core.type.AnnotationMetadata
;
import
org.springframework.data.envers.repository.config.EnableEnversRepositories
;
import
org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean
;
import
org.springframework.data.jpa.repository.JpaRepository
;
...
...
@@ -43,6 +45,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import
org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension
;
import
org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean
;
import
org.springframework.data.repository.history.RevisionRepository
;
import
org.springframework.util.ClassUtils
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's JPA Repositories.
...
...
@@ -74,6 +77,7 @@ import org.springframework.data.repository.history.RevisionRepository;
@ConditionalOnMissingBean
({
JpaRepositoryFactoryBean
.
class
,
JpaRepositoryConfigExtension
.
class
})
@ConditionalOnProperty
(
prefix
=
"spring.data.jpa.repositories"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
@Import
(
JpaRepositoriesImportSelector
.
class
)
@AutoConfigureAfter
({
HibernateJpaAutoConfiguration
.
class
,
TaskExecutionAutoConfiguration
.
class
})
public
class
JpaRepositoriesAutoConfiguration
{
...
...
@@ -115,17 +119,21 @@ public class JpaRepositoriesAutoConfiguration {
}
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
(
EnableEnversRepositories
.
class
)
@Import
(
EnversRevisionRepositoriesRegistrar
.
class
)
public
static
class
EnversRevisionRepositoriesRegistrarConfiguration
{
static
class
JpaRepositoriesImportSelector
implements
ImportSelector
{
}
private
static
final
boolean
ENVERS_AVAILABLE
=
ClassUtils
.
isPresent
(
"org.springframework.data.envers.repository.config.EnableEnversRepositories"
,
JpaRepositoriesImportSelector
.
class
.
getClassLoader
());
@Override
public
String
[]
selectImports
(
AnnotationMetadata
importingClassMetadata
)
{
return
new
String
[]
{
determineImport
()
};
}
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnMissingClass
(
"org.springframework.data.envers.repository.config.EnableEnversRepositories"
)
@Import
(
JpaRepositoriesRegistrar
.
class
)
public
static
class
JpaRepositoriesRegistrarConfiguration
{
private
String
determineImport
()
{
return
ENVERS_AVAILABLE
?
EnversRevisionRepositoriesRegistrar
.
class
.
getName
(
)
:
JpaRepositoriesRegistrar
.
class
.
getName
();
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/AbstractJpaRepositoriesAutoConfigurationTests.java
View file @
6505e03c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/EnversRevisionRepositoriesAutoConfigurationTests.java
View file @
6505e03c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfigurationTests.java
View file @
6505e03c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/city/City.java
View file @
6505e03c
/*
* Copyright 2012-20
20
the original author or authors.
* Copyright 2012-20
19
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.
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/city/CityRepository.java
View file @
6505e03c
/*
* Copyright 2012-20
20
the original author or authors.
* Copyright 2012-20
19
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.
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/country/Country.java
View file @
6505e03c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/country/CountryRepository.java
View file @
6505e03c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
spring-boot-project/spring-boot-docs/build.gradle
View file @
6505e03c
...
...
@@ -100,6 +100,7 @@ dependencies {
implementation
(
"org.springframework.data:spring-data-cassandra"
)
implementation
(
"org.springframework.data:spring-data-couchbase"
)
implementation
(
"org.springframework.data:spring-data-elasticsearch"
)
implementation
(
"org.springframework.data:spring-data-envers"
)
implementation
(
"org.springframework.data:spring-data-jpa"
)
implementation
(
"org.springframework.data:spring-data-ldap"
)
implementation
(
"org.springframework.data:spring-data-mongodb"
)
...
...
@@ -226,6 +227,7 @@ tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
"spring-boot-version"
:
project
.
version
,
"spring-data-commons-version"
:
versionConstraints
[
"org.springframework.data:spring-data-commons"
],
"spring-data-couchbase-version"
:
versionConstraints
[
"org.springframework.data:spring-data-couchbase"
],
"spring-data-envers-version"
:
versionConstraints
[
"org.springframework.data:spring-data-envers"
],
"spring-data-jdbc-version"
:
versionConstraints
[
"org.springframework.data:spring-data-jdbc"
],
"spring-data-jpa-version"
:
versionConstraints
[
"org.springframework.data:spring-data-jpa"
],
"spring-data-mongodb-version"
:
versionConstraints
[
"org.springframework.data:spring-data-mongodb"
],
...
...
spring-boot-project/spring-boot-docs/src/docs/asciidoc/attributes.adoc
View file @
6505e03c
...
...
@@ -60,6 +60,8 @@
:spring-data-couchbase-docs: https://docs.spring.io/spring-data/couchbase/docs/{spring-data-couchbase-version}/reference/html/
:spring-data-elasticsearch: https://spring.io/projects/spring-data-elasticsearch
:spring-data-elasticsearch-docs: https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/
:spring-data-envers: https://spring.io/projects/spring-data-envers
:spring-data-envers-doc: https://docs.spring.io/spring-data/envers/docs/{spring-data-envers-version}/reference/html/
:spring-data-gemfire: https://spring.io/projects/spring-data-gemfire
:spring-data-geode: https://spring.io/projects/spring-data-geode
:spring-data-jpa: https://spring.io/projects/spring-data-jpa
...
...
spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/sql.adoc
View file @
6505e03c
...
...
@@ -247,6 +247,21 @@ For complete details, see the {spring-data-jpa-docs}[Spring Data JPA reference d
[[features.sql.jpa-and-spring-data.envers-repositories]]
==== Spring Data Envers Repositories
If {spring-data-envers}[Spring Data Envers] is available, JPA repositories are auto-configured to support typical Envers queries.
To use Spring Data Envers, make sure your repository extends from `RevisionRepository` as show in the following example:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/jpaandspringdata/repositories/CountryRepository.java[]
----
NOTE: For more details, check the {spring-data-envers-doc}[Spring Data Envers reference documentation].
[[features.sql.jpa-and-spring-data.creating-and-dropping]]
==== Creating and Dropping JPA Databases
By default, JPA databases are automatically created *only* if you use an embedded database (H2, HSQL, or Derby).
...
...
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/sql/jpaandspringdata/entityclasses/Country.java
0 → 100644
View file @
6505e03c
/*
* Copyright 2012-2021 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
*
* https://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
.
features
.
sql
.
jpaandspringdata
.
entityclasses
;
import
java.io.Serializable
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
org.hibernate.envers.Audited
;
@Entity
public
class
Country
implements
Serializable
{
@Id
@GeneratedValue
private
Long
id
;
@Audited
@Column
(
nullable
=
false
)
private
String
name
;
public
Long
getId
()
{
return
this
.
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/sql/jpaandspringdata/repositories/CountryRepository.java
0 → 100644
View file @
6505e03c
/*
* Copyright 2012-2021 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
*
* https://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
.
features
.
sql
.
jpaandspringdata
.
repositories
;
import
org.springframework.boot.docs.features.sql.jpaandspringdata.entityclasses.Country
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.repository.Repository
;
import
org.springframework.data.repository.history.RevisionRepository
;
public
interface
CountryRepository
extends
RevisionRepository
<
Country
,
Long
,
Integer
>,
Repository
<
Country
,
Long
>
{
Page
<
Country
>
findAll
(
Pageable
pageable
);
}
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