Java 弹簧靴&x2B;JPA-SharedEntityManagerCreator在启动时打开会话
给定以下设置:Java 弹簧靴&x2B;JPA-SharedEntityManagerCreator在启动时打开会话,java,spring,hibernate,spring-mvc,jpa,Java,Spring,Hibernate,Spring Mvc,Jpa,给定以下设置: 弹簧靴1.4 Hibernate 5/多租户启用/多租户策略为数据库 spring.jpa.open-in-view=true,spring.jpa.properties.hibernate.hbm2ddl.auto=none,spring.jpa.properties.hibernate.temp.use\u jdbc\u metadata\u defaults=false,spring.jpa.properties.hibernate.dial=org.hibernate.
- 弹簧靴1.4
- Hibernate 5/多租户启用/多租户策略为数据库
,spring.jpa.open-in-view=true
,spring.jpa.properties.hibernate.hbm2ddl.auto=none
,spring.jpa.properties.hibernate.temp.use\u jdbc\u metadata\u defaults=false
spring.jpa.properties.hibernate.dial=org.hibernate.dial.postgresqldatal
n
编号奇怪地等于@org.springframework.transaction.annotation.Transactional(readOnly=true)
注释的方法编号
我还注意到,负责打开这些会话的组件是org.springframework.orm.jpa.SharedEntityManagerCreator
,正是代码的以下部分:
@覆盖
公共对象调用(对象代理、方法、对象[]args)抛出Throwable{
//...
布尔值isNewEm=false;
if(target==null){
debug(“为共享EntityManager调用创建新的EntityManager”);
target=(!CollectionUtils.isEmpty(this.properties)?
this.targetFactory.createEntityManager(this.properties):
这个.targetFactory.createEntityManager());
isNewEm=真;
}
//...
}
下面是一个屏幕截图,显示被代理的方法
话虽如此,我的问题是:
对于这种行为有什么解释吗?因为我希望在应用程序完全启动之前,或者在启动过程中需要数据操作(加载模式)(这不是我的情况)…不会打开任何会话。Spring Boot JPA starter的transitives拉入tomcat jdbc,我相信它会连接池,使用tomcat dbcp IIRC。此代码来自调用处理程序,因此您需要知道代理的是哪个方法。也许你可以设置一个断点,在调用堆栈上做一个屏幕截图。