Repository navigation
Considered new defaults for JPA repository bootstrap #16230
Description
Activity
- addedstatus: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged
on Mar 14, 2019 I wonder if going lazy for
SpringBootTestandDataJpaTestis a good idea.When creating a brand new project using initializr, a single test is typically created:
contextLoads.This test, as far as I understand, is meant to check that the context loads correctly, and thus that the application won't throw any exception once executed.
I understand that this is of course only one test, and that many others should be created, but still: with JPA repositories loaded lazily, this test will pass even though, for example, one of the JPA queries is invalid.
And, if DataJpaTest also uses lazy, if just one of the repositories happens not to be tested and is never injected anywhere, then an invalid JPA query in this repository will go unnoticed in tests.
Being faster is nice, but when it comes to tests, I'd rather have tests that are a tiny bit slower but that detect bugs.
What do you think?
Reacted by Oliver Drotbohm and AlexI'm not in favour of any default that increases the risk of deploying something that's broken. Fast startup is all well and good, but I don't think it should be done at the expense of correctness. Other frameworks have made a different choice, and that may turn out to work well for their users, but I think it would be a mistake for us to follow suit purely to speed up startup time or test execution time.
Rather than making
@SpringBootTestor@DataJpaTestlazy by default, I'd prefer to add some of the discussion in this blog post to our reference documentation, along with some examples showing how lazy initialization can be enabled in tests (@SpringBootTest(properties="spring.main.lazy-initialization=true")should be all it takes). We could also consider an attribute on the@…Testannotations to make it even easier to opt in.Reacted by JB Nizet, Vedran Pavic, Oliver Drotbohm, Drew Vogel and Reginaldo SantosWhat are your thoughts of adding this optimizations as defaults in just spring boot devtools to improve the development experience?
Thanks for the feedback everyone. Very good points included. I guess I've been focussing too much on the how, whereas my actual concern was to make it very easy to make use of these configuration options.
I totally agree that we by no means should change the defaults in a way that currently working scenarios (like the general application bootstrap test that @jnizet described) should start to behave different in a less constraining way.
The proposal for making
deferredthe default still stands as the end result of the initialization is still equivalent to the current default, it just allows the asynchronousEntityManagerFactoryinitialization to take most effect possible.Regarding the lazy initialization, I agree that making it the default for DevTools is a good idea. For the test cases, my primary goal was to avoid spending time on initializing beans that are not required by a particular test. For
@Data…Test, there shouldn't be a need to initialize any repositories that are not injected into the test class. The ones injected will be fully initialized on first interaction. This should make practically no difference to the user experience as potential misconfigurations are still detected. Slightly later, but still. In fact, making other repositories lazy by default would result in those tests not fail due to bootstrap errors of unrelated repositories and thus provide a more precise picture of what's wrong exactly.As far as I can see this is currently needed to lazify repositories for such tests:
@DataJpaTests @TestPropertySource(properties = "spring.data.jpa.repositories.bootstrap-mode=lazy") class MyTests { … }
I wonder if this could be shortcutted to an attribute on the
@Data…Testannotations and default to lazy with the option for users to opt out of this again.- addedfor: team-attentionAn issue we'd like other members of the team to reviewAn issue we'd like other members of the team to reviewtype: enhancementA general enhancementA general enhancementand removedfor: team-attentionAn issue we'd like other members of the team to reviewAn issue we'd like other members of the team to reviewstatus: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged
on Nov 20, 2019 We're going to:
- Switch the default to
deferredfor normal running and@SpringBootTest - Switch to
lazyfor@Data…Test - Add an attribute to
@Data…Testthat uses theBootstrapModeannotation to change the default
- Switch the default to
- Switch to lazy for
@Data…Test - Add an attribute to
@Data…Testthat uses theBootstrapModeannotation to change the default
I'm not sure what the
...should mean in the@Data...Testannotations mentioned above, but JPA repositories are the only type of repositories that have abootstrapModeattribute on their respective@Enable...Repositoriesannotation in Spring Data, and the only type with abootstrap-modeproperty for Spring Boot auto-configuration.In addition, it is not currently possible to have more than one Spring Data repository configured with
BootstrapMode.DEFERRED(see https://jira.spring.io/browse/DATAJPA-1672). Changing the default toDEFERREDfor all types of repositories would have the potential to break any application that included more than one Spring DataRepositoryof any type.For these two reasons, we should change the default to
DEFERREDonly forJpaRepositoriesandLAZYonly for@DataJpaTest, leaving the default asDEFAULTfor all other types of Repositories.Reacted by Andy Wilkinson and Matt Corbett- Switch to lazy for
11 remaining items
I must have missed the change to the default, but this change affected both the projects I updated. Both intermittently would hang on start up and also when running tests. Changing the bootstrap mode back to
defaultseems to have fixed it (so far so good). I'm not usingorg.hibernate.search.FieldBridgeso I'm not sure my issue is the same as spring-projects/spring-framework#25111, but it was definitely a deadlock.@ctmay4 if you have the time, it would be great if you could capture and share a thread dump when things are deadlocked.
I've filed an issue for Spring Framework and @jhoeller seemed positive to be able to avoid a fix for the needed default constructor with the framework itself.
Reacted by Markus ZehnderHere is the thread dump when startup is hanging.
"main@1" prio=5 tid=0x1 nid=NA waiting java.lang.Thread.State: WAITING blocks task-1@7519 at jdk.internal.misc.Unsafe.park(Unsafe.java:-1) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:194) at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:447) at java.util.concurrent.FutureTask.get(FutureTask.java:190) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.getNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:540) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(AbstractEntityManagerFactoryBean.java:497) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:680) at com.sun.proxy.$Proxy93.getMetamodel(Unknown Source:-1) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean$$Lambda$859.436399072.apply(Unknown Source:-1) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.util.Iterator.forEachRemaining(Iterator.java:133) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.getMetamodels(JpaMetamodelMappingContextFactoryBean.java:106) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:80) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:44) at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:142) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$318.1466413743.getObject(Unknown Source:-1) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) - locked <0x273d> (a java.util.concurrent.ConcurrentHashMap) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1699) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1444) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$318.1466413743.getObject(Unknown Source:-1) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1114) at org.springframework.data.repository.support.Repositories.cacheRepositoryFactory(Repositories.java:99) - locked <0x273e> (a org.springframework.data.repository.support.Repositories) at org.springframework.data.repository.support.Repositories.populateRepositoryFactoryInformation(Repositories.java:92) at org.springframework.data.repository.support.Repositories.<init>(Repositories.java:85) at org.springframework.data.repository.support.DomainClassConverter.setApplicationContext(DomainClassConverter.java:109) at org.springframework.data.web.config.SpringDataWebConfiguration.addFormatters(SpringDataWebConfiguration.java:130) at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.addFormatters(WebMvcConfigurerComposite.java:81) at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.addFormatters(DelegatingWebMvcConfiguration.java:78) at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration.mvcConversionService(WebMvcAutoConfiguration.java:435) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$318.1466413743.getObject(Unknown Source:-1) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1306) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:539) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$318.1466413743.getObject(Unknown Source:-1) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) - locked <0x273f> (a java.lang.Object) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) at com.imsweb.seerdms.admin.AdminApplication.main(AdminApplication.java:34) "task-1@7519" prio=5 tid=0x181 nid=NA waiting for monitor entry java.lang.Thread.State: BLOCKED waiting for main@1 to release lock on <0x273d> (a java.util.concurrent.ConcurrentHashMap) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:183) at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:517) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:533) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:505) at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:265) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1472) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1269) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353) at org.springframework.orm.hibernate5.SpringBeanContainer.createBean(SpringBeanContainer.java:147) at org.springframework.orm.hibernate5.SpringBeanContainer.getBean(SpringBeanContainer.java:105) at org.hibernate.resource.beans.internal.ManagedBeanRegistryImpl.getBean(ManagedBeanRegistryImpl.java:61) at org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor.createManagedBean(ClassBasedConverterDescriptor.java:38) at org.hibernate.boot.model.convert.internal.AbstractConverterDescriptor.createJpaAttributeConverter(AbstractConverterDescriptor.java:107) at org.hibernate.mapping.SimpleValue.buildAttributeConverterTypeAdapter(SimpleValue.java:570) at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:531) at org.hibernate.cfg.annotations.SimpleValueBinder.fillSimpleValue(SimpleValueBinder.java:511) at org.hibernate.cfg.SetSimpleValueTypeSecondPass.doSecondPass(SetSimpleValueTypeSecondPass.java:25) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1693) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1651) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:286) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1214) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1245) at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$$Lambda$769.882838692.call(Unknown Source:-1) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) at java.util.concurrent.FutureTask.run(FutureTask.java:-1) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.lang.Thread.run(Thread.java:834) "Catalina-utility-1@7279" prio=1 tid=0x17e nid=NA waiting java.lang.Thread.State: WAITING at jdk.internal.misc.Unsafe.park(Unsafe.java:-1) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:234) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2123) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1182) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1054) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1114) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:834) "Catalina-utility-2@7283" prio=1 tid=0x17f nid=NA waiting java.lang.Thread.State: WAITING at jdk.internal.misc.Unsafe.park(Unsafe.java:-1) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:194) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2081) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1177) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1054) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1114) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:834) "RMI Scheduler(0)@3836" daemon prio=5 tid=0x13 nid=NA waiting java.lang.Thread.State: WAITING at jdk.internal.misc.Unsafe.park(Unsafe.java:-1) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:234) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2123) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1182) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1054) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1114) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.lang.Thread.run(Thread.java:834) "HikariPool-1 housekeeper@8907" daemon prio=5 tid=0x184 nid=NA waiting java.lang.Thread.State: WAITING at jdk.internal.misc.Unsafe.park(Unsafe.java:-1) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:234) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2123) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1182) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1054) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1114) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.lang.Thread.run(Thread.java:834) "Common-Cleaner@1773" daemon prio=8 tid=0xa nid=NA waiting java.lang.Thread.State: WAITING at java.lang.Object.wait(Object.java:-1) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:155) at jdk.internal.ref.CleanerImpl.run(CleanerImpl.java:148) at java.lang.Thread.run(Thread.java:834) at jdk.internal.misc.InnocuousThread.run(InnocuousThread.java:134) "RMI TCP Accept-0@1714" daemon prio=5 tid=0x10 nid=NA runnable java.lang.Thread.State: RUNNABLE at java.net.PlainSocketImpl.accept0(PlainSocketImpl.java:-1) at java.net.PlainSocketImpl.socketAccept(PlainSocketImpl.java:159) at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:458) at java.net.ServerSocket.implAccept(ServerSocket.java:565) at java.net.ServerSocket.accept(ServerSocket.java:533) at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:52) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:394) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:366) at java.lang.Thread.run(Thread.java:834) "RMI TCP Connection(1)-172.22.34.23@3482" daemon prio=5 tid=0x12 nid=NA runnable java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(SocketInputStream.java:-1) at java.net.SocketInputStream.socketRead(SocketInputStream.java:115) at java.net.SocketInputStream.read(SocketInputStream.java:168) at java.net.SocketInputStream.read(SocketInputStream.java:140) at java.io.BufferedInputStream.fill(BufferedInputStream.java:252) at java.io.BufferedInputStream.read(BufferedInputStream.java:271) - locked <0x2742> (a java.io.BufferedInputStream) at java.io.FilterInputStream.read(FilterInputStream.java:83) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:544) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$222.498706880.run(Unknown Source:-1) at java.security.AccessController.doPrivileged(AccessController.java:-1) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.lang.Thread.run(Thread.java:834) "container-0@7293" prio=5 tid=0x180 nid=NA sleeping java.lang.Thread.State: TIMED_WAITING at java.lang.Thread.sleep(Thread.java:-1) at org.apache.catalina.core.StandardServer.await(StandardServer.java:570) at org.springframework.boot.web.embedded.tomcat.TomcatWebServer$1.run(TomcatWebServer.java:197) "Reference Handler@10043" daemon prio=10 tid=0x2 nid=NA runnable java.lang.Thread.State: RUNNABLE at java.lang.ref.Reference.waitForReferencePendingList(Reference.java:-1) at java.lang.ref.Reference.processPendingReferences(Reference.java:241) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:213) "Finalizer@9857" daemon prio=8 tid=0x3 nid=NA waiting java.lang.Thread.State: WAITING at java.lang.Object.wait(Object.java:-1) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:155) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:176) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:170) "Signal Dispatcher@10044" daemon prio=9 tid=0x4 nid=NA runnable java.lang.Thread.State: RUNNABLE "Attach Listener@3193" daemon prio=5 tid=0x5 nid=NA runnable java.lang.Thread.State: RUNNABLEThanks, @ctmay4, that's very helpful. It looks like issue is caused by the Spring Data web integration being triggered and that trying to look up repositories during initialization and thus ending up waiting to be able to use the JPA meta-model currently in creation.
I think
DomainClassConverteris a decent place to delay that initialization until the first use of the converter.In our case, we are using repositories during application startup
Thread dump at 0:08.725.872 * Thread group "main": Thread "main": at jdk.internal.misc.Unsafe.park(boolean, long) at java.util.concurrent.locks.LockSupport.park(java.lang.Object) (line: 194) at java.util.concurrent.FutureTask.awaitDone(boolean, long) (line: 447) at java.util.concurrent.FutureTask.get() (line: 190) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.getNativeEntityManagerFactory() (line: 540) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(java.lang.reflect.Method, java.lang.Object[ ]) (line: 497) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[ ]) (line: 680) at com.sun.proxy.$Proxy135.getMetamodel() at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean$$Lambda$824.1357311524.apply(java.lang.Object) at java.util.stream.ReferencePipeline$3$1.accept(java.lang.Object) (line: 195) at java.util.Iterator.forEachRemaining(java.util.function.Consumer) (line: 133) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(java.util.function.Consumer) (line: 1801) at java.util.stream.AbstractPipeline.copyInto(java.util.stream.Sink, java.util.Spliterator) (line: 484) at java.util.stream.AbstractPipeline.wrapAndCopyInto(java.util.stream.Sink, java.util.Spliterator) (line: 474) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(java.util.stream.PipelineHelper, java.util.Spliterator) (line: 913) at java.util.stream.AbstractPipeline.evaluate(java.util.stream.TerminalOp) (line: 234) at java.util.stream.ReferencePipeline.collect(java.util.stream.Collector) (line: 578) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.getMetamodels() (line: 106) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance() (line: 80) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance() (line: 44) at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet() (line: 142) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(java.lang.String, java.lang.Object, org.springframework.beans.factory.support.RootBeanDefinition) (line: 1855) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(java.lang.String, java.lang.Object, org.springframework.beans.factory.support.RootBeanDefinition) (line: 1792) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 595) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 323) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$311.852190062.getObject() at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(java.lang.String, org.springframework.beans.factory.ObjectFactory) (line: 226) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(java.lang.String, java.lang.Class, java.lang.Object[ ], boolean) (line: 321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(java.lang.String) (line: 202) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(java.lang.Object, org.springframework.beans.factory.config.RuntimeBeanReference) (line: 330) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(java.lang.Object, java.lang.Object) (line: 113) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(java.lang.String, org.springframework.beans.factory.config.BeanDefinition, org.springframework.beans.BeanWrapper, org.springframework.beans.PropertyValues) (line: 1699) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, org.springframework.beans.BeanWrapper) (line: 1444) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 594) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 323) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$311.852190062.getObject() at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(java.lang.String, org.springframework.beans.factory.ObjectFactory) (line: 226) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(java.lang.String, java.lang.Class, java.lang.Object[ ], boolean) (line: 321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(java.lang.String) (line: 202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(java.lang.String, java.lang.Class, org.springframework.beans.factory.BeanFactory) (line: 276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(org.springframework.beans.factory.config.DependencyDescriptor, java.lang.String, java.util.Set, org.springframework.beans.TypeConverter) (line: 1306) at org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver$1.getTarget() (line: 90) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[ ]) (line: 192) at com.sun.proxy.$Proxy183.findAll() at com.faforever.api.i18n.RepositoryMessageSource.loadMessages() (line: 30) at com.faforever.api.i18n.RepositoryMessageSource.afterPropertiesSet() (line: 79) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(java.lang.String, java.lang.Object, org.springframework.beans.factory.support.RootBeanDefinition) (line: 1855) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(java.lang.String, java.lang.Object, org.springframework.beans.factory.support.RootBeanDefinition) (line: 1792) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 595) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 323) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$311.852190062.getObject() at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(java.lang.String, org.springframework.beans.factory.ObjectFactory) (line: 226) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(java.lang.String, java.lang.Class, java.lang.Object[ ], boolean) (line: 321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(java.lang.String) (line: 202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(java.lang.String, java.lang.Class, org.springframework.beans.factory.BeanFactory) (line: 276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(org.springframework.beans.factory.config.DependencyDescriptor, java.lang.String, java.util.Set, org.springframework.beans.TypeConverter) (line: 1306) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(org.springframework.beans.factory.config.DependencyDescriptor, java.lang.String, java.util.Set, org.springframework.beans.TypeConverter) (line: 1226) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(java.lang.Object, java.lang.String, org.springframework.beans.PropertyValues) (line: 715) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(java.lang.Object, java.lang.String, org.springframework.beans.PropertyValues) (line: 130) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(org.springframework.beans.PropertyValues, java.lang.Object, java.lang.String) (line: 399) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, org.springframework.beans.BeanWrapper) (line: 1422) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 594) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 323) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$311.852190062.getObject() at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(java.lang.String, org.springframework.beans.factory.ObjectFactory) (line: 226) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(java.lang.String, java.lang.Class, java.lang.Object[ ], boolean) (line: 321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(java.lang.String) (line: 202) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons() (line: 895) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) (line: 878) at org.springframework.context.support.AbstractApplicationContext.refresh() (line: 550) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh() (line: 143) at org.springframework.boot.SpringApplication.refresh(org.springframework.context.ConfigurableApplicationContext) (line: 758) at org.springframework.boot.SpringApplication.refresh(org.springframework.context.ApplicationContext) (line: 750) at org.springframework.boot.SpringApplication.refreshContext(org.springframework.context.ConfigurableApplicationContext) (line: 397) at org.springframework.boot.SpringApplication.run(java.lang.String[ ]) (line: 315) at org.springframework.boot.SpringApplication.run(java.lang.Class[ ], java.lang.String[ ]) (line: 1237) at org.springframework.boot.SpringApplication.run(java.lang.Class, java.lang.String[ ]) (line: 1226) at com.faforever.api.FafApiApplication.main(java.lang.String[ ]) (line: 15) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.lang.reflect.Method, java.lang.Object, java.lang.Object[ ]) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[ ]) (line: 62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[ ]) (line: 43) at java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[ ]) (line: 566) at com.intellij.rt.execution.application.AppMainV2.main(java.lang.String[ ]) (line: 128) Thread "task-1": at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(java.lang.String, boolean) (line: 183) at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(java.lang.String, org.springframework.core.ResolvableType, boolean) (line: 517) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(org.springframework.core.ResolvableType, boolean, boolean) (line: 533) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(java.lang.Class, boolean, boolean) (line: 505) at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(org.springframework.beans.factory.ListableBeanFactory, java.lang.Class, boolean, boolean) (line: 265) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(java.lang.String, java.lang.Class, org.springframework.beans.factory.config.DependencyDescriptor) (line: 1472) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(org.springframework.beans.factory.config.DependencyDescriptor, java.lang.String, java.util.Set, org.springframework.beans.TypeConverter) (line: 1269) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(org.springframework.beans.factory.config.DependencyDescriptor, java.lang.String, java.util.Set, org.springframework.beans.TypeConverter) (line: 1226) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(java.lang.Object, java.lang.String, org.springframework.beans.PropertyValues) (line: 715) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(java.lang.Object, java.lang.String, org.springframework.beans.PropertyValues) (line: 130) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(org.springframework.beans.PropertyValues, java.lang.Object, java.lang.String) (line: 399) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, org.springframework.beans.BeanWrapper) (line: 1422) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 594) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[ ]) (line: 517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(java.lang.Class, int, boolean) (line: 353) at org.springframework.orm.hibernate5.SpringBeanContainer.createBean(java.lang.Class, org.hibernate.resource.beans.container.spi.BeanContainer$LifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer) (line: 147) at org.springframework.orm.hibernate5.SpringBeanContainer.getBean(java.lang.Class, org.hibernate.resource.beans.container.spi.BeanContainer$LifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer) (line: 105) at org.hibernate.resource.beans.internal.ManagedBeanRegistryImpl.getBean(java.lang.Class) (line: 61) at org.hibernate.jpa.event.internal.CallbackBuilderLegacyImpl.resolveEntityCallbacks(org.hibernate.annotations.common.reflection.XClass, org.hibernate.jpa.event.spi.CallbackType, org.hibernate.annotations.common.reflection.ReflectionManager) (line: 200) at org.hibernate.jpa.event.internal.CallbackBuilderLegacyImpl.buildCallbacksForEntity(java.lang.String, org.hibernate.jpa.event.spi.CallbackBuilder$CallbackRegistrar) (line: 74) at org.hibernate.event.service.internal.EventListenerRegistryImpl.prepare(org.hibernate.boot.spi.MetadataImplementor) (line: 146) at org.hibernate.boot.internal.MetadataImpl.initSessionFactory(org.hibernate.engine.spi.SessionFactoryImplementor) (line: 376) at org.hibernate.internal.SessionFactoryImpl.<init>(org.hibernate.boot.spi.MetadataImplementor, org.hibernate.boot.spi.SessionFactoryOptions) (line: 211) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build() (line: 468) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build() (line: 1249) at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(javax.persistence.spi.PersistenceUnitInfo, java.util.Map) (line: 58) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory() (line: 365) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory() (line: 391) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$$Lambda$769.2071551415.call() at java.util.concurrent.FutureTask.run() (line: 264) at java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) (line: 1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run() (line: 628) at java.lang.Thread.run() (line: 834)- added a commit that references this issue
on May 26, 2020 - added 4 commits that reference this issue
on May 29, 2020 Not sure if related to this change since setting spring.data.jpa.repositories.bootstrap-mode=default
in my test application properties doesn't seem to help, but upgrading from 2.2.7 to 2.3.0 I see the following behavior:- Aspects around repositories show that the entityManager is 'open', but the underlying Session is in the 'closed' state.
- 'could not initialize proxy' --> no Session exceptions when calling save on the repository.
For #1 we inject an entityManager in the aspect and noticed that the session is closed. This is only happening in the test environment; starting the war and calling some rest endpoint that calls in the end the repository does have the session 'open'.
For #2. The following scenario:
entityB = entityBrepository.findOne(id); <--- returns a proxied entity
entityA = new entityA(entityB);
entityArepository.save(entityA) <-- could not initialize proxy- no Session exception.Tests are annotated as follows:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@ContextConfiguration
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)Update 1:
Mmm, might be a different issue altogether. We have a bean that listens to the ContextRefreshEvent and loads data if so configured. Here is when I see the above failures. But I noticed that when I use this bean at application startup (so outside the integration test environment) it has the same errors. Again this is all working in 2.2.7Update 2:
So in 2.2.7 I receive 1 ContextRefreshEvent with source AnnotationConfigServletWebServerApplicationContext
With 2.3.0 I receive 2 of those events from the same source. If I discard the first event and only try to load data when I receive the event the second time, the above errors magically disappear.
So either I need to listen to a different event or that first event is emitted too soon?
Anyhow this discussion probably should move elsewhere, just no clue where.@basven Could you please open a new issue so that we can investigate? A minimal sample that reproduces the problem would be much appreciated. If you are receiving two
ContextRefreshedEvents that's either a bug or there are two contexts involved. The latter would be true if you have configuredmanagement.server.portto run Actuator's HTTP endpoints on a separate port. This hasn't changed between 2.2 and 2.3 so may well not be the cause.I've run into this after updating to Spring Boot 2.3.3 from 2.2
So far I've only seen deadlocks in my tests.
Deadlocks seem to have disappeared after switiching my DataJpaTests to
BootstrapMode.DEFAULTand settingspring.data.jpa.repositories.bootstrap-modetodefault.A Thread Dump looks somewhat similar to ctmay4's:
JpaMetamodelMappingContext seems to be instantiated as a dependency of
org.springframework.data.auditing.AuditingHandler."main@1" prio=5 tid=0x1 nid=NA waiting java.lang.Thread.State: WAITING blocks task-1@24187 at jdk.internal.misc.Unsafe.park(Unsafe.java:-1) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:194) at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:447) at java.util.concurrent.FutureTask.get(FutureTask.java:190) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.getNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:540) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(AbstractEntityManagerFactoryBean.java:497) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:680) at com.sun.proxy.$Proxy212.getMetamodel(Unknown Source:-1) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean$$Lambda$1393.242040834.apply(Unknown Source:-1) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.util.Iterator.forEachRemaining(Iterator.java:133) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.getMetamodels(JpaMetamodelMappingContextFactoryBean.java:106) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:80) at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:44) at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:142) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$514.890491412.getObject(Unknown Source:-1) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) - locked <0x5eec> (a java.util.concurrent.ConcurrentHashMap) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113) at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:690) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$514.890491412.getObject(Unknown Source:-1) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) - locked <0x5f3a> (a java.lang.Object) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) - locked <0x5f31> (a org.springframework.test.context.cache.DefaultContextCache) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:123) at org.springframework.cloud.contract.wiremock.WireMockTestExecutionListener.applicationContextBroken(WireMockTestExecutionListener.java:125) at org.springframework.cloud.contract.wiremock.WireMockTestExecutionListener.beforeTestClass(WireMockTestExecutionListener.java:41) at org.springframework.test.context.TestContextManager.beforeTestClass(TestContextManager.java:213) at org.springframework.test.context.junit.jupiter.SpringExtension.beforeAll(SpringExtension.java:77) at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$7(ClassBasedTestDescriptor.java:359) at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor$$Lambda$279.154449611.execute(Unknown Source:-1) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:359) at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:189) at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:78) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:132) at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$236.330551672.execute(Unknown Source:-1) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$235.644052207.invoke(Unknown Source:-1) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$234.1652764753.execute(Unknown Source:-1) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService$$Lambda$240.1309129055.accept(Unknown Source:-1) at java.util.ArrayList.forEach(ArrayList.java:1541) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$236.330551672.execute(Unknown Source:-1) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$235.644052207.invoke(Unknown Source:-1) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$234.1652764753.execute(Unknown Source:-1) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248) at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211) at org.junit.platform.launcher.core.DefaultLauncher$$Lambda$189.1824837049.accept(Unknown Source:-1) at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) "task-1@24187" prio=5 tid=0x82 nid=NA waiting for monitor entry java.lang.Thread.State: BLOCKED waiting for main@1 to release lock on <0x5eec> (a java.util.concurrent.ConcurrentHashMap) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:986) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:884) at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:619) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:536) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:503) at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:265) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1473) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1270) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:715) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353) at org.springframework.orm.hibernate5.SpringBeanContainer.createBean(SpringBeanContainer.java:147) at org.springframework.orm.hibernate5.SpringBeanContainer.getBean(SpringBeanContainer.java:105) at org.hibernate.resource.beans.internal.ManagedBeanRegistryImpl.getBean(ManagedBeanRegistryImpl.java:61) at org.hibernate.jpa.event.internal.CallbackBuilderLegacyImpl.resolveEntityCallbacks(CallbackBuilderLegacyImpl.java:200) at org.hibernate.jpa.event.internal.CallbackBuilderLegacyImpl.buildCallbacksForEntity(CallbackBuilderLegacyImpl.java:74) at org.hibernate.event.service.internal.EventListenerRegistryImpl.prepare(EventListenerRegistryImpl.java:146) at org.hibernate.boot.internal.MetadataImpl.initSessionFactory(MetadataImpl.java:379) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:213) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:469) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1259) at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$$Lambda$930.2131482093.call(Unknown Source:-1) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) at java.util.concurrent.FutureTask.run(FutureTask.java:-1) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.lang.Thread.run(Thread.java:834)@hgarus thank you for the report and sorry this is causing an issue for you. As indicated in the comment just above yours, could you please create a separate issue with a small sample that we can use to reproduce the issue?
Spring Boot 2.1 exposes a property
spring.data.jpa.repositories.bootstrap-modethat can be set todefault(default)deferredorlazy. I suggest do change the default value for property to be changed in the following scenarios:deferred– it parallelizes the bootstrap of theEntityManagerFactoryand delays repository initialization to the end of theApplicationContextinitialization. I.e. there are performance benefits to the startup but the app is the same state as with the current default once it has been started.lazyfor@SpringBootTest,@DataJpaTest– this leaves all but repositories injected into the tests initialized which gives a bit of a performance boost in both scenarios.