使用jpa启动时间慢

Hi,我公司项目使用spring-boot-starter-data-jpa启动时会卡主较长时间(20多分钟),卡在日志打印:“j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit ‘default’” 处。我讲日志等级改为debug时,发现一直循环报下面这个错误,请问一下这个启动慢的问题如何排查,网上我没搜到答案

javax.management.InstanceNotFoundException: org.springframework.boot:type=Admin,name=SpringApplication
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095) ~[na:1.8.0_291]
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:643) ~[na:1.8.0_291]
	at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:678) ~[na:1.8.0_291]
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1445) ~[na:1.8.0_291]
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) ~[na:1.8.0_291]
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) ~[na:1.8.0_291]
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) ~[na:1.8.0_291]
	at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:639) ~[na:1.8.0_291]
	at sun.reflect.GeneratedMethodAccessor92.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_291]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_291]
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) ~[na:1.8.0_291]
	at sun.rmi.transport.Transport$1.run(Transport.java:200) [na:1.8.0_291]
	at sun.rmi.transport.Transport$1.run(Transport.java:197) [na:1.8.0_291]
	at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_291]
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196) [na:1.8.0_291]
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573) [na:1.8.0_291]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) [na:1.8.0_291]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) [na:1.8.0_291]
	at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_291]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) [na:1.8.0_291]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_291]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_291]
	at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_291]

这个异常日志是因为默认加载了 jmx 的原因

RunEdit ConfigurationEnable JMX agent 勾选项去掉

嗯嗯,这个勾选项我去掉后就一直卡在:

2021-11-22 14:22:29.059 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.annotation.InjectionMetadata     : Registered injected element on class [cdp.framework.config.JpaConfig]: PersistenceElement for private javax.persistence.EntityManager cdp.framework.config.JpaConfig.entityManager
2021-11-22 14:22:29.059 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Eagerly caching bean 'jpaConfig' to allow for resolving potential circular references
2021-11-22 14:22:29.059 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.annotation.InjectionMetadata     : Processing injected element of bean 'jpaConfig': PersistenceElement for private javax.persistence.EntityManager cdp.framework.config.JpaConfig.entityManager
2021-11-22 14:22:29.063 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'entityManagerFactory'
2021-11-22 14:22:29.063 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.cache.config.internalCacheAdvisor'
2021-11-22 14:22:29.063 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2021-11-22 14:22:29.063 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.retry.annotation.RetryConfiguration'
2021-11-22 14:22:29.063 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'sleuthAdvisorConfig'
2021-11-22 14:22:29.063 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.cache.config.internalCacheAdvisor'
2021-11-22 14:22:29.063 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2021-11-22 14:22:29.063 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'org.springframework.retry.annotation.RetryConfiguration'
2021-11-22 14:22:29.063 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'sleuthAdvisorConfig'
2021-11-22 14:22:29.068 DEBUG [weCardAPI,,,] 21844 --- [           main] o.s.jdbc.datasource.DataSourceUtils      : Fetching JDBC Connection from DataSource

好像一直连数据库连不上,我问问公司的人吧 谢谢

没错呢,看日志的话。是一直卡在获取数据库连接上了。你可以尝试把数据库切换为本地,再次启动试试看。就可以确定是不是这个问题了。