eclipse / jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Repository injection doesn't work

amoscatelli opened this issue · comments

I am using Wildfly 21.0.0 (so I have CDI/Weld as required)

public interface StringValueRepository extends Repository<StringValue, String> {

}

Any combination of

@Produces
@Database(DatabaseType.KEY_VALUE)
protected BucketManager produce() {
    return manager;
}

or

@Produces
protected BucketManager produce() {
    return manager;
}

Isn't enough to inject

@Inject
@Database(DatabaseType.KEY_VALUE)
private StringValueRepository repository;

or

@Inject
private StringValueRepository repository;

org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type StringValueRepository with qualifiers @database

or

org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type StringValueRepository with qualifiers @default

Of course if the Produces method returns a StringValueRepository directly, then it works.

Since this kind of "indirect" injection is mentioned in different parts of jnosql spec/documentation I wonder what I am doing wrong :

http://www.jnosql.org/spec/
http://www.jnosql.org/docs/key-value.html

In Wildfly logs I can read :
19:44:37,453 INFO [org.eclipse.jnosql.mapping.reflection.ClassConverter] (MSC service thread 1-8) Scanned the entity org.visiontech.optoplus.bucket.manager.producer.StringValue loaded with time of 4 ms
19:44:37,619 INFO [org.eclipse.jnosql.mapping.Databases] (MSC service thread 1-8) Found the type KEY_VALUE to metadata KEY_VALUE@dynamodb
19:44:37,686 INFO [org.eclipse.jnosql.mapping.keyvalue.spi.KeyValueExtension] (MSC service thread 1-8) Processing Key-Value extension: 1 databases crud 0 found
19:44:37,686 INFO [org.eclipse.jnosql.mapping.keyvalue.spi.KeyValueExtension] (MSC service thread 1-8) Processing repositories as a Key-Value implementation: []

Little help please ?

Thank you in advance

This seems related to:
#239

But that was closed without explanation.

Can't say in detail here but keep in mind, Wildfly uses a different REST implementation than Glassfish or Payara, so the Jersey-related issues or steps may not apply at all.

I don't think the rest implementation is relevant, I believe this is a problem related to the CDI implementation and/or bean discovery.

I am investigating more.
There is something wrong here, inside KeyValueExtension, that is not working in my case :

<T extends Repository> void observes(@Observes final ProcessAnnotatedType<T> repo) {
    Class<T> javaClass = repo.getAnnotatedType().getJavaClass();

    if (Repository.class.equals(javaClass)) {
        return;
    }

    if (Arrays.asList(javaClass.getInterfaces()).contains(Repository.class)
            && Modifier.isInterface(javaClass.getModifiers())) {
        crudTypes.add(repo.getAnnotatedType().getJavaClass());
    }
}

Oh I got it.
bean.xml was missing.
When beans.xml is missing default scanning is for annotated types only.
The interface StringValueRepository is not annotated so to be scanned it requires bean-discovery-mode="all".
Sorry for the fuss, it's working now.

p.s. maybe this could be mentioned somewhere in the guide, when in the example you have to create the interface, I believe there should be a warning about enabling the all discovery mode to make it work.