GH-10 - Explicitly order JpaEventPublicationAutoConfiguration before general JPA setup.

This commit is contained in:
Oliver Drotbohm
2022-07-12 23:55:02 +02:00
parent 3eaea6dea7
commit da278f7774
5 changed files with 89 additions and 4 deletions

View File

@@ -64,10 +64,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>test</scope>
</dependency>

View File

@@ -16,11 +16,17 @@
package org.springframework.modulith.events.jpa;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.Configuration;
/**
* Auto-configuration for JPA based event publication. Registers this class' package as auto-configuration package, so
* that it gets picked up for entity scanning by default.
*
* @author Oliver Drotbohm
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(HibernateJpaAutoConfiguration.class)
@AutoConfigurationPackage
class JpaEventPublicationAutoConfiguration {}

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2022 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 example;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author Oliver Drotbohm
*/
@SpringBootApplication
public class ExampleApplication {}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2022 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.modulith.events.jpa;
import static org.assertj.core.api.Assertions.*;
import example.ExampleApplication;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.modulith.events.EventSerializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.TestConstructor.AutowireMode;
/**
* @author Oliver Drotbohm
*/
@SpringBootTest
@ContextConfiguration(classes = ExampleApplication.class)
@TestConstructor(autowireMode = AutowireMode.ALL)
@RequiredArgsConstructor
class JpaEventPublicationAutoConfigurationIntegrationTests {
private final BeanFactory factory;
@MockBean EventSerializer serializer;
@Test // GH-10
void registersJpaEventPublicationPackageForAutoConfiguration() {
var examplePackage = ExampleApplication.class.getPackageName();
var eventPublicationPackage = JpaEventPublication.class.getPackageName();
assertThat(AutoConfigurationPackages.get(factory))
.containsExactlyInAnyOrder(examplePackage, eventPublicationPackage);
}
}

View File

@@ -40,7 +40,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@TestConstructor(autowireMode = AutowireMode.ALL)
@RequiredArgsConstructor
public class JpaEventPublicationConfigurationIntegrationTests {
class JpaEventPublicationConfigurationIntegrationTests {
private final ApplicationContext context;