quarkusio/quarkus · error · RuntimeException
'@Inject' cannot be used with a
Error message
'@Inject' cannot be used with a '${ResteasyReactiveDotNames.APPLICATION}' class. Offending class is: '${selectedAppClass.name()}' What it means
The detected JAX-RS Application subclass declares a CDI @Inject field (or constructor), which RESTEasy Reactive does not support on Application classes. Application classes are instantiated reflectively by the scanner outside the CDI context, so injection cannot be performed.
Solutions
- Remove @Inject members from the Application class and obtain needed values statically or via constructor parameters.
- Move resource registration from the Application class to CDI beans (@Path resources discovered automatically) so no injection is needed.
- Use org.eclipse.microprofile.config.ConfigProvider.getConfig() inside the Application instead of @Inject Config.
Example fix
// before
class MyApp extends Application {
@Inject
MyService service;
}
// after
class MyApp extends Application {
private final MyService service = ConfigProvider.getConfig()
.getValue("my.service", MyService.class);
} Defensive patterns
Strategy: validation
Validate before calling
// before building
for (Field f : appClass.getDeclaredFields())
if (f.isAnnotationPresent(Inject.class))
throw new IllegalStateException("@Inject not allowed on Application class: " + appClass.getName()); Prevention
- Never annotate Application class members with @Inject
- Use ConfigProvider.getConfig() for static config access in Application classes
- Keep Application classes limited to getClasses()/getSingletons() overrides
When it happens
Trigger: scanForApplicationClass finds an Application subclass where appClassHasInject(...) returns true, i.e. the class has @Inject annotated members.
Common situations: Injecting a config property or service into the Application class to compute getClasses()/getSingletons(); migrating a Quarkus (CDI-friendly) app to RESTEasy Reactive where the old pattern relied on injection.
Related errors
- More than one Application class
- Usage of '@Inject' is not allowed in…
- A receiver method must have exactly one parameter annotated…
- A receiver method must not be private:
- A receiver method must not be static:
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/0e8aa0e2fb361c1a.
Report an issue: GitHub.
Appendix: source
Thrown at independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveScanner.java:96
Set<String> singletonClasses = new HashSet<>();
Set<String> globalNameBindings = new HashSet<>();
boolean filterClasses = !excludedClasses.isEmpty();
Application application = null;
ClassInfo selectedAppClass = null;
BlockingDefault blocking = BlockingDefault.AUTOMATIC;
for (ClassInfo applicationClassInfo : applications) {
if (Modifier.isAbstract(applicationClassInfo.flags())) {
continue;
}
if (excludedClasses.contains(applicationClassInfo.name().toString())) {
continue;
}
if (selectedAppClass != null) {
throw new RuntimeException("More than one Application class: " + applications);
}
selectedAppClass = applicationClassInfo;
if (appClassHasInject(selectedAppClass)) {
throw new RuntimeException("'@Inject' cannot be used with a '" + ResteasyReactiveDotNames.APPLICATION
+ "' class. Offending class is: '" + selectedAppClass.name() + "'");
}
String applicationClass = applicationClassInfo.name().toString();
try {
Class<?> appClass = Thread.currentThread().getContextClassLoader().loadClass(applicationClass);
application = (Application) appClass.getConstructor().newInstance();
Set<Class<?>> classes = application.getClasses();
if (!classes.isEmpty()) {
for (Class<?> klass : classes) {
allowedClasses.add(klass.getName());
}
filterClasses = true;
}
classes = application.getSingletons().stream().map(Object::getClass).collect(Collectors.toSet());
if (!classes.isEmpty()) {
for (Class<?> klass : classes) {
allowedClasses.add(klass.getName());
singletonClasses.add(klass.getName());View on GitHub (pinned to e1c734241f)