deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gerhard Petracek <gerhard.petra...@gmail.com>
Subject Re: CDI in ConfigSource
Date Wed, 01 Jun 2016 17:23:15 GMT
short addition:

you can have a look at an example at [1].

regards,
gerhard

[1]
http://cdiatwork.irian.at/book_de/introduction.html#!idx:/deltaspike.html:fig:db_aware_config-source

http://www.irian.at

Your JavaEE powerhouse -
JavaEE Consulting, Development and
Courses in English and German

Professional Support for Apache
MyFaces, DeltaSpike and OpenWebBeans

2016-06-01 19:10 GMT+02:00 Gerhard Petracek <gerhard.petracek@gmail.com>:

> hi kevin,
>
> if the cdi-container isn't ready at the first access, you can just check
> it via:
>
> public String getPropertyValue(String key) {
>   if (!BeanManagerProvider.isActive() || key.startsWith("deltaspike.")) {
>     return null;
>   }
>   //...
> }
>
> you need to return null for those lookups and once the cdi-container is
> ready, you can access your cdi-beans.
> (skip keys used by deltaspike, if your config-source provides values for
> your custom keys.)
>
> regards,
> gerhard
>
> http://www.irian.at
>
> Your JavaEE powerhouse -
> JavaEE Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache
> MyFaces, DeltaSpike and OpenWebBeans
>
>
>
> 2016-06-01 17:50 GMT+02:00 Kevin Gr√ľneberg <kgrueneberg@eos-uptrade.de>:
>
>> Hello,
>>
>> is there any way to get CDI working in a ConfigSource?
>>
>> Basically, I am trying to define a custom ConfigSource, that injects a
>> DAO to retreive the configuration parameters from a database. However, the
>> ConfigSource is registered via META-INF/Services and the class is loaded
>> very early, even before JNDI lookup or anything else works.
>>
>> What I tried, for example, is something like
>>
>> public class DatabaseConfigSource implements ConfigSource {
>>
>> @Inject
>>
>> private ConfigDao configDao;
>>
>> public String getPropertyValue(String key) {
>>
>> if (configDao == null) {
>>
>> BeanProvider.injectFields(this);
>>
>> }
>>
>> }
>>
>> }
>>
>> I cannot call BeanProvider.injectFields(this), because the class is
>> instantiated so early, that there is no CDI context available.
>>
>> Is there a way to get CDI to work for a custom ConfigSource?
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message