【发布时间】:2018-03-22 15:34:17
【问题描述】:
我有一个 Spring-Boot Web 应用程序,并且我有一个具有数据访问层的 3rd 方 jar。为了使用它,我必须向它发送一个对 EntityManagerFactory 的引用。我可以这样做:
Map<String, String> stg = new HashMap<String, String>();
stg.put("hibernate.connection.url", "jdbc:mysql://localhost:3306/mydb");
stg.put("hibernate.connection.username", "name");
stg.put("hibernate.connection.password", "password");
EntityManagerFactory fact = MultipleEntityManagerFactoryHolder.getEmf("stg", stg);
但是当我将它添加到 application.properties 时,如何获得 Spring(我假设)已经为我构建的那个:
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?useSSL=false
spring.datasource.username=user
spring.datasource.password=password
我无法访问 jar,所以我需要工厂,而不是 DataSource。有谁知道如何获得它?
【问题讨论】:
-
我理解你的问题吗?您想使用基于属性文件条目的实体管理器将属性添加到您的地图吗?
标签: java spring spring-mvc jpa spring-boot