Java EE: CDI Fails when using constructor injection

I'm creating a backend service implementation for a bunch of interfaces and to have the cleanest code possible, I decided to move to Constructor based DI instead of Field based, but it gave me headaches.

Using WebLogic 12.1.3, this class gets instantiated properly:

@Stateless(name = "MenuService")

@Slf4j

public class MenuFacade implements MenuService {

@Inject

private MenuRepository menuRepository;

@Inject

private MenuMapper menuMapper;

public MenuFacade(MenuRepository menuRepository, MenuMapper menuMapper) {

this.menuRepository = menuRepository;

this.menuMapper = menuMapper;

}

public MenuFacade() {

}

@Override

@Transactional

public List getMenuList() {

log.trace("Fetching Menu entities from database");

List menuEntities = menuRepository.findAll();

log.trace("Menu entities: {}", menuEntities);

return menuEntities.stream().map(menuMapper::menuEntityToMenuDto).collect(Collectors.toList());

}

}

However, when I try to refactor it like this:

@Stateless(name = "MenuService")

@Slf4j

public class...

Read More »

By: StackOverFlow - 7 days ago

Related Posts