0
votes

My beans.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                       http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       version="1.1" bean-discovery-mode="annotated">
</beans>

My service (backend - type EJB) looks like this:

import javax.inject.Inject;
import javax.transaction.Transactional;

@Default
@Transactional(Transactional.TxType.REQUIRED)
public class UserServiceImpl implements UserService {

@Inject
private UserDao userDao;

@Inject
private UserMapper mapper;

and @Named annotated bean uses this (web):

import javax.inject.Inject;
import javax.inject.Named;
import org.omnifaces.cdi.ViewScoped;

@ViewScoped
@Named("indexMBean")
public class IndexMBean extends AbstractViewBean {

    @Inject
    private UserService userService;

Build was success, but deploy gives me this exception:

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UserService with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private hu.food.bean.IndexMBean.userService

how can I set the Default injection for UserService?

the log says:

2018-11-12 11:28:25,706 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."kaJava-ear-0.0.1-SNAPSHOT.ear".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."kaJava-ear-0.0.1-SNAPSHOT.ear".WeldStartService: Failed to start service at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1728) at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1556) at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378) at java.lang.Thread.run(Thread.java:748) Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UserService with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private hu.food.bean.IndexMBean.userService at hu.food.bean.IndexMBean.userService(IndexMBean.java:0)

2
It shows your code is missing dependency injection, show all logs or attache file that we can easily track itDeedar Ali Brohi
@DeedarAliBrohi attached a logMysticUnicorn
Have you tried with totally empty beans.xml so not even elements <?xml ... or<beans/>?pirho

2 Answers

4
votes

You set bean-discovery mode to annotated. so only beans annotated with a scope type will be detected

bean-discovery-mode="annotated">

please add a scope type annotation like @dependent to your bean

@Default
@Transactional(Transactional.TxType.REQUIRED)
@Dependent
public class UserServiceImpl implements UserService {

http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#bean_defining_annotations says:

The set of bean defining annotations contains:

  • @ApplicationScoped, @SessionScoped, @ConversationScoped and
  • @RequestScoped annotations,

  • all other normal scope types,

  • @Interceptor and @Decorator annotations,

  • all stereotype annotations (i.e. annotations annotated with @Stereotype),

  • and the @Dependent scope annotation.

1
votes

You are using annotated discovery mode in your beans.xml this means that only beans with so called Bean defining annotations are discovered and registered as beans. Consult CDI spec for all the annotations that belong there; for your use case, you are missing bean scope.

If you remove @Default qualifier from UserServiceImpl (it is useless, it is added there anyway; spec link) and add a scope to the bean, it should work. Based on how your bean should behave (from the lifecycle point of view), you can make it @ApplicationScoped, @SessionScoped, @RequestScoped, @ConversationScoped, @Dependent (, @Singleton).