jsr107 / jsr107spec

JSR107 Cache Specification
Apache License 2.0
413 stars 164 forks source link

Proper annotation for injecting cache with CDI? #397

Open Quix0r opened 6 years ago

Quix0r commented 6 years ago

Hi,

I currently use fish.payara.cdi.jsr107.impl.NamedCache for naming my CDI-injected cache. Excerpt from my code (which will be GNU AGPLv3 but that is not relevant here):

    /**
     * Cached products
     */
    @Inject
    @NamedCache (cacheName = "productCache")
    private Cache<Long, Product> productCache;

By Product is a POJI for an entity and Long is the entity's persisted primary key (aka. "insert-id").

This currently works flawless, except that I have a warning in my IDE: "Unsatisfied dependency: no bean matches the injection point". this.productCache is immediately available, even in a @PostConstruct annotated method.

As I said, it works (not flawless due to the warning) but it feels not right as it makes my project depending on a specific release of Payara (they are around here, too) as the needed payara-api.jar seem to be updated (e.g. it just happened from 173 to 174 build) sometimes and then I need to update it in my project, too. Plus I need to ask my users to have that specific build.

I would love to see this annotation being fixed (by Payara, of course) and then included into JS107 specs.

cruftex commented 5 years ago

Injecting in containers was discussed here: https://github.com/jsr107/jsr107spec/issues/208

Quix0r commented 4 years ago

So how is it done?