1

I added in pom.xml

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>8.0</version>
    <scope>provided</scope>
</dependency>

And normally CDI should just be provided by this dependency.

I deploy my war on a Payara micro server.

But all the @Inject annotations are not working. All the objects are still null.

For example I have this class:

@ApplicationScoped
public class GreetingService {

    public String getGreetingTemplate(String language) {
        String result = "Hello %s";
        switch (language) {
        case "fr":
            result = "Bonjour %s";
            break;
        case "de":
            result = "Willkommen, %s";
            break;
        }
        return result;
    }
}

Then I do

@Stateless
public class MyClassImpl implements MyClass {

    @Inject
    private GreetingService greetingService;
      :

Whatever I do greetingService always is null. I have beans.xml even I read since Java EE 7 it is no longer required. I even set it to bean-discovery-mode="all" .

It already gives me headache. I really have not a single clue.

Toni26
  • 489
  • 4
  • 11
  • Where is MyClassImpl called from and how? It is already being injected by CDI? – Pablo AM Aug 29 '21 at 15:23
  • I made MyClassImpl also be injected in a Controller. It turns out it is also null. Seems CDI is not working across whole application . javax.inject.Inject is the namespace – Toni26 Aug 29 '21 at 20:53
  • Which Payara version are you using? Which flavour? I have created a dummy project and deploy in payara and it is working as expected. Can you provide your actual code? And pom? – Pablo AM Aug 30 '21 at 17:52

1 Answers1

0

try to add a beans.xml to your project with property: bean-discovery-mode="all"

Tadas B.
  • 176
  • 8