2 Replies Latest reply on Nov 2, 2016 1:47 PM by Max Barkley

    Problem with @Inject (Unsatisfied dependencies)

    Errai User Newbie

      Hi,

      i am using Errai for several months - everything works fine without any problem - i really enjoy using Errai.

      Yesterday i tried to add a Bean outside the client package (Test.java in dev package) an and tried to inject some other stuff, but this does not work as expected.


      My project structure:

      com.mydomain.myapp.client

      com.mydomain.myapp.shared

      com.mydomain.myapp.server

      com.mydomain.myapp.dev (newly added)

       

      Myapp.gwt.xml:

      located on com.mydomain.myapp

      <module ...>

          ....

        <source path='client' />

        <source path='shared' />

         <!-- (new) -->

        <source path='dev' />

      </module>


      Within client package in my EntrPoint class:

      @AfterInitialization

      public void start() {

      Test test = new Test();

      test.execute();

      }

       

      Test.java:

      package com.mydomain.myapp.dev;

      import javax.enterprise.context.Dependent;

      import javax.inject.Inject;

      import org.jboss.errai.ui.client.local.spi.TranslationService;

      import com.google.gwt.user.client.Window;

       

      @Dependent

      public class Test {

       

        @Inject

        private TranslationService i18n;

       

        public void execute() {

        Window.alert("Executing Test");

        }

      }

       

      Error I:

      [0mERROR [org.jboss.msc.service.fail] MSC000001: Failed to start service jboss.deployment.unit."myapp.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."myapp.war".WeldStartService: Failed to start service

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_31]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_31]

        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_31]

      Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type TranslationService with qualifiers @Default

        at injection point [BackedAnnotatedField] @Inject private com.mydomain.myapp.dev.Test.i18n

        com.mydomain.myapp.dev.Test.i18n(Test.java:0)

       

      If i try to inject one of my services (Errai RPC) in the Test class - i get a different error: ->

       

      Error II:
      [ERROR] Error generating BootstrapperImpl

      java.util.concurrent.ExecutionException: org.jboss.errai.ioc.rebind.ioc.exception.UnsatisfiedDependenciesException:  @> com.mydomain.myapp.dev.Test

      - field org.jboss.errai.codegen.meta.MetaField:Test.@javax.inject.Inject() private  com.mydomain.myapp.shared.rpc.UserServices userService could not be satisfied for type: com.mydomain.myapp.shared.rpc.UserServices

        Message: can't resolve bean: com.mydomain.myapp.shared.rpc.UserServices ( @Default )

       

      I am using Errai 3.2.2.Final with Wildfly-8.2.0.Final (Started with EmbeddedWildFlyLauncher in Eclipse)

      It seems like every attempt to inject something in Test.java fails. If i remove the injection points i can use the Test Class in my client package.

       

      This is a working, deployable Errai setup / project - all things in the client, shared and server packages work as expected - only the newly added Test File in the "dev" package fails to work if i try to inject something

      Are there any Errai or GWT configuration options to make this work?

       

      Any hints?

      Thanks!

                 

        • 1. Re: Problem with @Inject (Unsatisfied dependencies)
          Errai User Newbie

          Hi,

           

          i solved this by using the annotation com.google.inject.Inject instead of javax.inject.Inject. This worked for me because we have only one java class in this package - some sort of status bean - containing only information about our local development environment.

           

          But i would be interested to know why using javax.inject.Inject fails.

          • 2. Re: Problem with @Inject (Unsatisfied dependencies)
            Max Barkley Expert

            Hi,

             

            Glad to hear you found a workaround. The reason you saw an error is because Weld was not able to find the TranslationService. There are lots of potential reasons why that could have happened, as TranslationService is a client-side type that is not meant to be deployed to an app server. By changing the @Inject annotation, you made it so the field was no longer a CDI injection point.

             

            Cheers.