Java EE 8 application failed to start on Wildfly 25 after adding Extension

Viewed 417

I am faced with a strange issue trying to create a custom Scope in my application.

I made minimal sample application to illustrate the problem.

Environment:

  • Java 11 (but same with 17 either)
  • Wildfly 25.0.0.Final

build.gradle:

plugins {
    id 'java'
    id 'war'
}

group 'com.example.extension'
version '1.0-SNAPSHOT'

sourceCompatibility = 11

war {
    archiveName 'extension.war'
}

repositories {
    mavenCentral()
}

dependencies {
    compileOnly group: 'jakarta.platform', name: 'jakarta.jakartaee-api', version: '8.0.0'
}

Main.java

package com.example.extension;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;

@Singleton
@Startup
public class Main {

    @Inject
    SampleClass sc;

    @PostConstruct
    public void init() {
        sc.sayHello();
    }
}

SampleClass.java

package com.example.extension;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class SampleClass {
    public void sayHello() {
        System.out.println("Hello world");
    }
}

At that stage everything is ok:

INFO [stdout] (ServerService Thread Pool -- 78) Hello world

But after adding a new empty class to the project

SampleExtension.java

package com.example.extension;

import javax.enterprise.inject.spi.Extension;

public class SampleExtension implements Extension { }

It starts to fail:

com.example.extension : extension.war: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."extension.war".component.Main.WeldInstantiator" => "Failed to start service Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type SampleClass with qualifiers @Default at injection point [BackedAnnotatedField] @Inject com.example.extension.Main.sc at com.example.extension.Main.sc(Main.java:0) "}}
com.example.extension : extension.war: Artifact is deployed successfully

I'm new in the Java EE world and I stuck with it. Please explain what is wrong with my code?

P.S. I've checked the same code using Jakarta EE 9.1 and GlassFish 6.2.2 (have to change imports from javax to jakarta) and there is no such issue.

1 Answers

Given you're adding a CDI extension you need to include a beans.xml in your deployment. Per the specification:

An archive which:

  • contains a beans.xml file with the bean-discovery-mode of none, or,

  • contains an extension and no beans.xml file

is not a bean archive.

Related