Unsatisfied dependencies for type […] with qualifiers [@Default] at injection point (using @Stateful EJB with CDI)

前端 未结 5 843
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 23:56

I have the following code to manage two kinds of repositories. Both repository classes inherit an interface to allow reinitialization of their resources.

pub         


        
相关标签:
5条回答
  • 2021-01-04 00:22

    I had the same problem. I hope this can help someone.

    To solve the problem:

    • Right click on projcet
    • Click on Properties
    • find Project facets
    • On Project facets, active the option CDI
    • Apply and save.

    Now all is fine.

    0 讨论(0)
  • 2021-01-04 00:24

    Maybe you should add non-parameterized Constructor on the bean class. I read on Jboss Documentation that says: concrete Java class that has a constructor with no parameters (or a constructor designated with the annotation @Inject) is a bean.

    0 讨论(0)
  • 2021-01-04 00:26

    I had the same error.

    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UserTransaction with qualifiers @Default at injection point [BackedAnnotatedField] @Inject...

    I solved this problem like this: I used UserTransaction this way when I received an error.

    @Inject
    UserTransaction trans;
    

    Instead of @Inject, I used @Resource annotation.

    0 讨论(0)
  • 2021-01-04 00:30

    I had the same problem with this misleading exception...

    By adding @Stateful to UserRepository you expose EJB methods of the CachingRepository interface without having a no-interface view declared. Add @LocalBean to UserRepository to activate the no-interface view. See EJB 3.1 Specification, Section 4.9.8 "Session Bean's No-Interface View"

    The bean class must designate that it exposes a no-interface view via its bean class definition or in the deployment descriptor. The following rules apply:

    • ...
    • If the bean exposes at least one other client view, the bean designates that it exposes a no-interface view by means of the @LocalBean annotation on the bean class or in the deployment descriptor.
    • ...

    I also refer to this stackoverflow answer for more information about no-interface views.

    0 讨论(0)
  • 2021-01-04 00:34

    I had the same problem.

    And this is what I did to resolve it:

    I had to produce the EJB I am trying to inject as below with a wildfly container:

    @ApplicationScoped
        public class Resources {
         private static final String DISCOUNT_SERVICE_ENDPOINT_PROPERTY =
            "services.discount.endpoint";
         private MyServiceImpl myService;
        }
    
    @Produces
     public MyServiceImpl produceMyServiceImpl() {
         if (myService == null) {
             String endpoint = System.getProperty(DISCOUNT_SERVICE_ENDPOINT_PROPERTY);
            JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
            factory.setServiceClass(MyServiceImpl.class);
            factory.setServiceName(MyService.SERVICE);
            factory.setAddress(endpoint);
            myService = (MyServiceImpl) factory.create();
         }
         return myService;
    

    }

    The below is a config which goes under your standalone-full.xml file.

    <property name="services.discount.endpoint" value="http://localhost:8080/my_service/MyService/MyServiceImpl"/>
    
    0 讨论(0)
提交回复
热议问题