javarepository-patterndeltaspike

Java SE + Apache DeltaSpike: Unsatisfied dependencies for type Repository


I'm trying to use the DeltaSpike Data module with Weld, but every class annotated with @Repository shows a warning in my IDE and an exception at runtime.

I've tried following the DeltaSpike documentation numerous times, checked Baeldung, and various articles/forums but have not found a solution.

Does anyone know what I might be missing to allow the repositories to be injected correctly?

IDE Warning

Managed Bean must be a concrete class or @Decorator

Runtime Exception

org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ExampleRepo with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public com.example.myapp.services.ExampleService(ExampleRepo)

Example Repository

@Repository(forEntity = Data.class)
public interface ExampleRepo extends EntityRepository<Example, Long> {

    Data findExampleById(long id);

    @Modifying
    @Query("UPDATE Data AS e SET e.locale = ?1 WHERE e.id = ?2")
    int updateLocale(final Locale locale, final long id);

    @Modifying
    @Query("UPDATE Data AS g SET g.reactTranslation = ?1 WHERE g.id = ?2")
    int updateReactTranslation(final boolean toggle, final long id);
}

Gradle

plugins {
    id "io.spring.dependency-management" version "1.0.8.RELEASE"
}

ext {
    deltaSpikeVersion = "1.9.2"
}

dependencies {
    // DeltaSpike Extensions
    implementation "org.apache.deltaspike.modules:deltaspike-data-module-api:${deltaSpikeVersion}"
    runtimeOnly "org.apache.deltaspike.modules:deltaspike-data-module-impl:${deltaSpikeVersion}"
    implementation "org.apache.deltaspike.modules:deltaspike-scheduler-module-api:${deltaSpikeVersion}"
    runtimeOnly "org.apache.deltaspike.modules:deltaspike-scheduler-module-impl:${deltaSpikeVersion}"

    // Database
    implementation "org.hibernate:hibernate-core:${hibernateVersion}"
    implementation "org.hibernate:hibernate-c3p0:${hibernateVersion}"
    runtimeOnly "mysql:mysql-connector-java:8.0.18"
}

dependencyManagement {
    imports {
        mavenBom "org.apache.deltaspike.distribution:distributions-bom:${deltaSpikeVersion}"
    }
}

To clarify, the following are also implicit dependencies of the project.


Solution

  • I missed a Java SE specific instruction: https://deltaspike.apache.org/documentation/cdiimp.html#javase6

    I had to use CdiContainer from DeltaSpike instead of SeContainer from Weld.

    dependencies {
        implementation "org.apache.deltaspike.cdictrl:deltaspike-cdictrl-api:${deltaSpikeVersion}"
        runtimeOnly "org.apache.deltaspike.cdictrl:deltaspike-cdictrl-weld:${deltaSpikeVersion}"
    }