MP-Config with EJB or CDI?

82 views
Skip to first unread message

Ralph Soika

unread,
Jun 7, 2019, 11:51:27 AM6/7/19
to Eclipse MicroProfile
Hi,
I try to implement a custom Microprofile Config Source. My property source is some data stored in a database.
After some testing with Wildlfy 15 it seems that a custom config Source is not part of the CDI lifecylce.
I did not find a way to get a JPA Entity Manger or a EJB injected. It looks to me that the Custom Config Source is created as a plain old Java bean.

My question is: is this behavior expected or is this because of a wildfly specific implementation?
I found a similar unanswered question on Stackoverflow.  

Does anybody knows how to inject EJBs into a custom config source?

Thanks for help

===
Ralph

Alasdair Nottingham

unread,
Jun 7, 2019, 11:54:22 AM6/7/19
to microp...@googlegroups.com
I recall in the early days a lot of discussion around this area and they were made POJO’s because if an EJB (which is a CDI bean) expected config to be injected into it at startup based on a ConfigSource that had dependencies on EJB’s you could get into startup looping issues.

I guess you could use JNDI to look it up, but again it may not be available when the ConfigSource is first loaded.

--
You received this message because you are subscribed to the Google Groups "Eclipse MicroProfile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to microprofile...@googlegroups.com.
To post to this group, send email to microp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/microprofile/fa4496b6-1471-4daf-92fb-302ce9b19402%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ralph Soika

unread,
Jun 7, 2019, 12:48:11 PM6/7/19
to Eclipse MicroProfile
Thanks for that information, this makes sense.
I solved the problem by simply declaring my local properties object static. Now I can overload the properties later when my CDI/EJB code is @PostConstruct ed
This works! I added my code example here.

Am Freitag, 7. Juni 2019 17:54:22 UTC+2 schrieb Alasdair Nottingham:
I recall in the early days a lot of discussion around this area and they were made POJO’s because if an EJB (which is a CDI bean) expected config to be injected into it at startup based on a ConfigSource that had dependencies on EJB’s you could get into startup looping issues.

I guess you could use JNDI to look it up, but again it may not be available when the ConfigSource is first loaded.
On Jun 7, 2019, at 11:51 AM, Ralph Soika <ralph...@imixs.com> wrote:

Hi,
I try to implement a custom Microprofile Config Source. My property source is some data stored in a database.
After some testing with Wildlfy 15 it seems that a custom config Source is not part of the CDI lifecylce.
I did not find a way to get a JPA Entity Manger or a EJB injected. It looks to me that the Custom Config Source is created as a plain old Java bean.

My question is: is this behavior expected or is this because of a wildfly specific implementation?
I found a similar unanswered question on Stackoverflow.  

Does anybody knows how to inject EJBs into a custom config source?

Thanks for help

===
Ralph



--
You received this message because you are subscribed to the Google Groups "Eclipse MicroProfile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to microp...@googlegroups.com.

Emily Jiang

unread,
Jun 10, 2019, 5:53:09 AM6/10/19
to Eclipse MicroProfile
Thank you Ralph for sharing your experiment! Would you like to write a blog on this: your problem, your solution, your finding? We can get this published under microprofile.io. Thoughts?

Thanks
Emily

Ralpus

unread,
Jun 11, 2019, 6:52:58 AM6/11/19
to microp...@googlegroups.com
He Emily,
Let me know what you think. You can share it if you like.
Best regards
Ralph

You received this message because you are subscribed to a topic in the Google Groups "Eclipse MicroProfile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/microprofile/WwMtst8ndik/unsubscribe.
To unsubscribe from this group and all its topics, send an email to microprofile...@googlegroups.com.

To post to this group, send email to microp...@googlegroups.com.

Phillip Krüger

unread,
Jun 11, 2019, 6:57:37 AM6/11/19
to Eclipse MicroProfile
Hi Ralph

Also have a look at the DB Config Source in the MicroProfile-ext project:

Cheers
To unsubscribe from this group and all its topics, send an email to microp...@googlegroups.com.

To post to this group, send email to microp...@googlegroups.com.

Emily Jiang

unread,
Jun 11, 2019, 11:22:57 AM6/11/19
to Eclipse MicroProfile
Thank you Ralph! I like your blog. Can you publish under microprofile.io/blog by clicking on "Become a MicroProfile Author" and then follow the instruction there?

Thanks
Emily
To unsubscribe from this group and all its topics, send an email to microp...@googlegroups.com.

To post to this group, send email to microp...@googlegroups.com.

Rhuan Henrique

unread,
Jun 12, 2019, 6:57:03 PM6/12/19
to MicroProfile
Hi @Ralpus 

In your post the custom ConfigSource is a singleton EJB, but another way to do that is getting EntityManager programmatically or creatting a EJB separated from ConfigSource and getting this EJB programatically using CDI. Using CDI you can get using this code to getnEJB programmatically.

         javax.enterprise.inject.spi.CDI.current().select(Ejb.class).get();

Thank you for share your experience!

Rhuan Rocha
SouJava Rio
  

To unsubscribe from this group and stop receiving emails from it, send an email to microprofile...@googlegroups.com.

To post to this group, send email to microp...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages