简体   繁体   English

JPA entityManager如何在Spring Boot Application中选择Connection Pool?

[英]How does JPA entityManager choose Connection Pool in Spring Boot Application?

I have 2 DAO - the first works with @Bean DataSource + JDBC .我有 2 个DAO - 第一个与 @Bean DataSource + JDBC 一起使用 Configuration is the following:配置如下:

@Bean("dataSource")
    @Singleton
    public DataSource getDataSource() {
        BasicDataSource basicDataSource = new BasicDataSource();
        basicDataSource.setDriverClassName("...");
        basicDataSource.setUrl("...");
        basicDataSource.setUsername(...);
        basicDataSource.setPassword(...);
        ...
        return basicDataSource;
    }

The second works with entityManager .第二个entityManager 一起使用 application.properties configuration is the following: application.properties配置如下:

spring.datasource.url=...
spring.datasource.username=...
spring.datasource.password=...
...

When I starts my Spring Boot Application and spring initializes my beans , I use the second DAO to get some information from database .当我启动我的Spring Boot 应用程序并且 spring 初始化我的bean 时,我使用第二个DAO 从数据库中获取一些信息。

I am using second DAO -> entityManager in this case.在这种情况下,我使用第二个DAO -> entityManager

I expects that entityManager uses configuration from application.properties .我希望entityManager使用application.properties 中的配置
Indeed, entityManager uses configration from bean DataSource .实际上, entityManager使用来自 bean DataSource 的配置

How does It work?它是如何工作的?
ps database properties in application.properties look like used. application.properties 中的ps数据库属性看起来像使用过。

Actually I think that I should use one ConnectionPool for my application.实际上,我认为我应该为我的应用程序使用一个ConnectionPool
I can configure DataSource as @Bean and provide entityManager and jdbcTemplate with It.我可以将DataSource配置为 @Bean 并为entityManagerjdbcTemplate提供它。
Should I choose another solution?我应该选择其他解决方案吗? Or Is this idea quite suitable?或者这个想法很合适吗?

It's because of the importance.这是因为重要性。 @Configuration has higher precedence than application.properties. @Configuration优先级高于 application.properties。 First spring-boot searches for @Bean definition, if it's not found, then it checks application.properties. spring-boot 首先搜索@Bean定义,如果没有找到,则检查application.properties。 Generally those definitions are equivalent.通常,这些定义是等效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法为事务打开JPA EntityManager-通信链接失败(Spring-boot / jpa / hibernate /连接池) - Could not open JPA EntityManager for transaction - Communications link failure (Spring-boot/jpa/hibernate/connection pool) 使用Spring Boot JPA覆盖数据源的连接池 - Overriding connection pool for datasource with Spring Boot JPA 我们如何知道,如果Spring Boot应用程序正在使用连接池 - How to do we know , if spring boot application is using connection pool 在Spring Boot应用程序中创建自定义连接池 - Creating custom connection pool in Spring Boot application 如何在spring jpa中管理数据库连接池? - How to manage database connection pool in spring jpa? Spring 启动 + Hibernate JPA 配置使用EntityManager - Spring Boot + Hibernate JPA configuration to use EntityManager Spring 启动 + Hibernate + JPA 没有事务实体管理器可用 - Spring boot + Hibernate + JPA No transactional EntityManager available 启动 Spring Boot 应用程序的默认 HikariCP 连接池 - Default HikariCP connection pool starting Spring Boot application 如何在Spring Boot休眠多租户应用程序中使用C3P0来管理连接池? - How to use C3P0 in a spring boot hibernate multi tenant application to manage connection pool? Spring Boot连接池的理解 - Spring boot connection pool understanding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM