我正在尝试编写注释来注入JMS资源。这是我的代码
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
我的制片人课有什么问题吗?
答案 0 :(得分:0)
根据beans.xml中定义的发现模式,您可能需要使用定义注释的bean(Dependent,ApplicationScoped或其他更适合的注释)来注释JMSResourceProducer。