Skip to content

Commit

Permalink
Add auto-configuration for Spring Data Envers
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Jul 28, 2020
1 parent 84bcd0e commit c5120a2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions spring-boot-project/spring-boot-autoconfigure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ dependencies {
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-rest-webmvc")
optional("org.springframework.data:spring-data-cassandra")
optional("org.springframework.data:spring-data-elasticsearch") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2012-2020 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.autoconfigure.data.jpa;

import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.env.Environment;
import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension;
import org.springframework.data.repository.config.BootstrapMode;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
import org.springframework.util.StringUtils;

import java.lang.annotation.Annotation;
import java.util.Locale;

/**
* {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Envers
* Repositories.
*
* @author Stefano Cordio
*/
class EnversRevisionRepositoriesRegistrar extends JpaRepositoriesRegistrar {

@Override
protected Class<?> getConfiguration() {
return EnableJpaRepositoriesConfiguration.class;
}

@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
private static class EnableJpaRepositoriesConfiguration {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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.orm.jpa.EntityManagerFactoryBuilderCustomizer;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
Expand All @@ -35,6 +36,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension;
Expand All @@ -57,6 +59,7 @@
* @author Phillip Webb
* @author Josh Long
* @author Scott Frederick
* @author Stefano Cordio
* @since 1.0.0
* @see EnableJpaRepositories
*/
Expand All @@ -66,10 +69,23 @@
@ConditionalOnMissingBean({ JpaRepositoryFactoryBean.class, JpaRepositoryConfigExtension.class })
@ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "enabled", havingValue = "true",
matchIfMissing = true)
@Import(JpaRepositoriesRegistrar.class)
@AutoConfigureAfter({ HibernateJpaAutoConfiguration.class, TaskExecutionAutoConfiguration.class })
public class JpaRepositoriesAutoConfiguration {

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(EnversRevisionRepositoryFactoryBean.class)
@Import(EnversRevisionRepositoriesRegistrar.class)
public static class EnversRevisionRepositoriesRegistrarConfiguration {

}

@Configuration(proxyBeanMethods = false)
@ConditionalOnMissingClass("org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean")
@Import(JpaRepositoriesRegistrar.class)
public static class JpaRepositoriesRegistrarConfiguration {

}

@Bean
@Conditional(BootstrapExecutorCondition.class)
public EntityManagerFactoryBuilderCustomizer entityManagerFactoryBootstrapExecutorCustomizer(
Expand Down

0 comments on commit c5120a2

Please sign in to comment.