类型QueueSession的CDI-不满意的依赖关系
问题描述:
我正在尝试编写注释来注入JMS资源。这里是我的代码类型QueueSession的CDI-不满意的依赖关系
public class JMSResourceProducer {
private static final String WL_INIT_CONN_FACTORY ="weblogic.jndi.WLInitialContextFactory";
private String WL_SERVER_URL = "URL";
private String QF ="QFNAME";
private String QQ ="QNAME";
public InitialContext createInitialContext() throws NamingException {
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY, WL_INIT_CONN_FACTORY);
properties.put(Context.PROVIDER_URL, WL_SERVER_URL);
return new InitialContext(properties);
}
@Produces @Image2000
public QueueSession createQueueSession() throws NamingException, JMSException {
InitialContext initialContext = createInitialContext();
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) initialContext.lookup(QF);
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
return queueConnection.createQueueSession(true, 0);
}
@Produces @Image2000
public Queue createQueue () throws NamingException {
InitialContext initialContext = createInitialContext();
Queue queue = (Queue)initialContext.lookup(QQ);
return queue;
}
}
这是我如何使用它在我的课
@Inject @Image2000
private QueueSession queueSession;
@Inject @Image2000
private Queue jmsQueue;
我的注释
@Qualifier
@Target({TYPE, METHOD, PARAMETER, FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Image2000 {
}
但我得到下面的错误我Wildfly启动时..
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type QueueSession with qualifiers @Image2000
注射时点[UnbackedAnnotatedField] @Inject @ Image2000 .queueSession
任何线索什么是我的生产者类错?
答
根据bean.xml中定义的发现模式,您可能需要使用定义注释的Bean(Dependent,ApplicationScoped或其他更适合的)来注释JMSResourceProducer。
+0
添加@依赖类解决了我的问题。谢谢jpangamarca – java2017 2015-03-23 05:54:37
+0
@ java2001不客气。 – jpangamarca 2015-03-23 14:00:02
您可以提供完整的日志,当Weld容器在'org.jboss.weld'记录器的'DEBUG'级别引导? JMSResourceProducer, – 2015-03-19 09:39:13
,似乎不是一个bean。使用'@Stateless'或'@ApplicationScope'对它进行注释 – maress 2015-03-19 15:44:51