Unsatisfied dependencies exeption when using bean with interface
janey Dec 28, 2010 5:33 AMHello,
I am using JBoss M4 with Weld and I am getting a DeploymentException. I generally know the reasons for such exceptions, but this time I cant get rid of it.
I implemented the following classes:
@Named @ConversationScoped @Stateful(name = "AccountHome") public class AccountHome extends HomeBean<Account, EntityManager> implements IAccount { // -- generated attribute, constant + association declarations ---------- @Inject private BankHome bankHome; @Inject private CustomerHome customerHome; [...] // methods left out for better reading }
and
@Named @ConversationScoped @Stateful(name = "BankHome") public class BankHome extends HomeBean<Bank, EntityManager> { // -- generated attribute, constant + association declarations ---------- @Inject private BankgroupHome bankgroupHome; @Inject private AccountHome accountHome; [...] // methods left out for better reading }
and the interface:
public interface IAccount { /** * method stub for further implementation * @param amount * @return */ public boolean withdraw(float amount); /** * method stub for further implementation * @param amount * @return */ public boolean deposit(float amount); /** * method stub for further implementation * @return */ public AccountStateEnum getState(); }
On deployment I am getting the following exception:
11:10:22,337 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Start: name=vfs:///D:/Studium/Masterarbeit/JBoss/jboss-6.0.0.20100721-M4/server/default/deploy/Bank.ear_WeldBootstrapBean state=Create: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Injection point has unsatisfied dependencies. Injection point: field Bank_Tutorial_Weld_Server.bankgroupServer.entity.BankHome.accountHome; Qualifiers: [@javax.enterprise.inject.Default()] at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:276) at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:122) at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:141) at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:331) at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:317) at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:399) at org.jboss.weld.integration.deployer.env.helpers.BootstrapBean.boot(BootstrapBean.java:121) [:6.0.0.20100721-M4] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_16] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_16] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_16] at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_16] at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:60) [jboss-reflect.jar:2.2.0.Alpha9]
I added the interface because I wanted to implement a decorator. So I created the following class:
@Decorator abstract class AccountChecker implements IAccount, Serializable { // -- generated attribute, constant + association declarations ---------- @Inject @Any @Delegate private IAccount account; [...] // methods left out for better reading }
Without the interface for class AccountHome and without the decorator I dont get the exception and everything works fine. But with the interface the injection point of the class BankHome cannot be resolved any more.
What am I missing? I searched the internet, the forum and the specification for answers, but couldnt find anything that explains the situation. I want to use a decorator but I also want to inject the concrete class AccountHome into the BankHome class. Why isnt that possible any more?
I rather expected to get an ambiguous dependency exception than a unsatisfied dependencies exception.
Any ideas?
Thanks Janey