最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to inject a specific EntityManager in Quarkus depending on the environment? - Stack Overflow

programmeradmin2浏览0评论

I'm working on a Quarkus application where I need to inject a specific EntityManager based on the environment:

In dev mode, I want to inject the EntityManager from a specific persistence unit ("result-db")

In test mode, I want to inject the default EntityManager without specifying a persistence unit.

I'm going through this because in my test mode i'm only dealing with one data source.

Here’s what I have for dev mode:

@PersistenceUnit("result-db")
EntityManager entityManager;

and for the test mode i want this injection:

@Inject
EntityManager entityManager;

I tried to use the @Produces and @IfBuildProfile annotations to achieve environment-specific injection, but it's not working as expected

I'm working on a Quarkus application where I need to inject a specific EntityManager based on the environment:

In dev mode, I want to inject the EntityManager from a specific persistence unit ("result-db")

In test mode, I want to inject the default EntityManager without specifying a persistence unit.

I'm going through this because in my test mode i'm only dealing with one data source.

Here’s what I have for dev mode:

@PersistenceUnit("result-db")
EntityManager entityManager;

and for the test mode i want this injection:

@Inject
EntityManager entityManager;

I tried to use the @Produces and @IfBuildProfile annotations to achieve environment-specific injection, but it's not working as expected

Share Improve this question asked Mar 13 at 9:54 Sergio AgüeroSergio Agüero 294 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Recently support for deactivated datasource was added to Quarkus (https://quarkus.io/guides/hibernate-orm#persistence-unit-active).
You can configure default and result-db PU in your application.properties and (de)activate using configuration profiles.

发布评论

评论列表(0)

  1. 暂无评论