Структура моего проекта следующая:
nl.daniel.dejong
- Application.java
- управление запасами
< ul>
домен
ProductService.java - Product.java
< li>ProductId.java
- ProductJpaPersistence .java
[*]выполнение заказа
- домен
OutboundOrder.java
- OutboundOrderJpaPersistence.java
Сохранения представляют собой JpaPersistence по умолчанию, использующие объект домена в качестве объекта домена, например:
Код: Выделить всё
@Repository
public interface ProductJpaPersistence extends ProductPersistence, JpaRepository
{
}
Код: Выделить всё
@SpringBootApplication
@EnableAsync
@ConfigurationPropertiesScan
@EnableJpaRepositories
public class Application {
public static void main(String... args) {
SpringApplication.run(Application.class, args);
}
}
Тест:
Код: Выделить всё
@ApplicationModuleTest
@RequiredArgsConstructor
class ProductIntegrationTest {
private static final String PRODUCT_NAME = "Product 1";
private final ProductService productService;
@Test
public void createProduct(Scenario scenario) {
var createProduct = new Product();
createProduct.setName(PRODUCT_NAME);
scenario.stimulate(() -> productService.create(createProduct))
.andWaitForEventOfType(ProductCreated.class)
.matchingMappedValue(ProductCreated::name, PRODUCT_NAME);
}
}
Код: Выделить всё
org.junit.jupiter.api.extension.ParameterResolutionException: Failed to resolve parameter [final nl.daniel.dejong.inventorymanagement.application.product.ProductService productService] in constructor [public nl.daniel.dejong.inventorymanagement.ProductIntegrationTest(nl.daniel.dejong.inventorymanagement.application.product.ProductService)]: Failed to load ApplicationContext for [WebMergedContextConfiguration@6ed000ba testClass = nl.daniel.dejong.inventorymanagement.ProductIntegrationTest, locations = [], classes = [nl.daniel.dejong.Application], contextInitializerClasses = [], activeProfiles = [], propertySourceLocations = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [[ImportsContextCustomizer@5862dc47 key = [org.springframework.modulith.test.ModuleTestAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@7857fe2, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@446a1e84, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@626abbd0, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@37313c84, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@415b0b49, org.springframework.modulith.test.ModuleContextCustomizerFactory$ModuleContextCustomizer@17503f8a, org.springframework.boot.test.context.SpringBootTestAnnotation@ab9d71ae], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, p a r e n t = n u l l ] < b r / > < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . P a r a m e t e r R e s o l u t i o n U t i l s . r e s o l v e P a r a m e t e r ( P a r a m e t e r R e s o l u t i o n U t i l s . j a v a : 1 5 9 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . P a r a m e t e r R e s o l u t i o n U t i l s . r e s o l v e P a r a m e t e r s ( P a r a m e t e r R e s o l u t i o n U t i l s . j a v a : 1 0 3 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . e x e c u t i o n . I n t e r c e p t i n g E x e c u t a b l e I n v o k e r . i n v o k e ( I n t e r c e p t i n g E x e c u t a b l e I n v o k e r . j a v a : 5 9 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . C l a s s B a s e d T e s t D e s c r i p t o r . i n v o k e T e s t C l a s s C o n s t r u c t o r ( C l a s s B a s e d T e s t D e s c r i p t o r . j a v a : 3 6 3 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . C l a s s B a s e d T e s t D e s c r i p t o r . i n s t a n t i a t e T e s t C l a s s ( C l a s s B a s e d T e s t D e s c r i p t o r . j a v a : 3 1 0 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . C l a s s T e s t D e s c r i p t o r . i n s t a n t i a t e T e s t C l a s s ( C l a s s T e s t D e s c r i p t o r . j a v a : 7 9 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . C l a s s B a s e d T e s t D e s c r i p t o r . i n s t a n t i a t e A n d P o s t P r o c e s s T e s t I n s t a n c e ( C l a s s B a s e d T e s t D e s c r i p t o r . j a v a : 2 8 6 ) < b r / > a t o r g . j u n i t . j u p i t e r . e n g i n e . d e s c r i p t o r . C l a s s B a s e d T e s t D e s c r i p t o r . l a m b d a $ t e s t I n s t a n c e s P r o v i d e r $ 4 (ClassBasedTestDescriptor.java:278)
at java.base/java.util.Optional.orElseGet(Optional.java:364)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$5(ClassBasedTestDescriptor.java:277)
at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$before$2(ClassBasedTestDescriptor.java:203)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:202)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:84)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:148)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@6ed000ba testClass = nl.daniel.dejong.inventorymanagement.ProductIntegrationTest, locations = [], classes = [nl.daniel.dejong.Application], contextInitializerClasses = [], activeProfiles = [], propertySourceLocations = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [[ImportsContextCustomizer@5862dc47 key = [org.springframework.modulith.test.ModuleTestAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@7857fe2, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@446a1e84, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@626abbd0, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@37313c84, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@415b0b49, org.springframework.modulith.test.ModuleContextCustomizerFactory$ModuleContextCustomizer@17503f8a, org.springframework.boot.test.context.SpringBootTestAnnotation@ab9d71ae], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:143)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:127)
at org.springframework.test.context.junit.jupiter.SpringExtension.getApplicationContext(SpringExtension.java:283)
at org.springframework.test.context.junit.jupiter.SpringExtension.resolveParameter(SpringExtension.java:269)
at org.junit.jupiter.engine.execution.ParameterResolutionUtils.resolveParameter(ParameterResolutionUtils.java:136)
... 51 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'outboundOrderJpaPersistence' defined in nl.daniel.dejong.orderfulfillment.infrastructure.persistence.OutboundOrderJpaPersistence defined in @EnableJpaRepositories declared on Application: Not a managed type: class nl.daniel.dejong.orderfulfillment.domain.order.OutboundOrder
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:967)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:942)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:137)
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)
at org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1406)
at org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:545)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:137)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:108)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:187)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:119)
... 55 more
Caused by: java.lang.IllegalArgumentException: Not a managed type: class nl.daniel.dejong.orderfulfillment.domain.order.OutboundOrder
at org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.managedType(JpaMetamodelImpl.java:192)
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:467)
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:97)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.(JpaMetamodelEntityInformation.java:82)
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:69)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:246)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:211)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:194)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:81)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:317)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:279)
at org.springframework.data.util.Lazy.getNullable(Lazy.java:245)
at org.springframework.data.util.Lazy.get(Lazy.java:114)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:285)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:132)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1817)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766)
... 76 more
PS: Описанная выше ситуация является представлением, максимально приближенным к полной реализации, но в ней может быть упущена некоторая информация. Опустил некоторые детали, чтобы не затмевать сообщение.
Я делаю что-то не так или это неожиданное поведение?
Редактировать: на самом деле удаление «EnableJpaRepositories» из «Application.Java». Я могу переопределить расположение репозитория, используя конфигурацию, содержащую «EnableJpaRepositories» в тесте. Я по-прежнему придерживаюсь мнения, что у SpringModulith должен быть способ сделать это самостоятельно.
Подробнее здесь: https://stackoverflow.com/questions/772 ... rent-modul