JMS 생산자 역할을하고 싶은 JavaEE 7에 구현 된 간단한 WebSocket이 있습니다. 나는 시도하고 주입 그러나, ConnectionFactory
및 Queue
JavaEE 어플로로를 @Resource
내가 항상 null 인 것을 알 수있다. 내 코드는 다음과 같습니다.
@Named
@ServerEndpoint("/hello")
public class WebSocketA implements Serializable {
@Resource(mappedName = "java:/JmsXA")
private ConnectionFactory connectionFactory = null;
@Resource(mappedName = "java:jboss/exported/jms/queue/test")
private Queue testQueue = null;
...
}
이들을 주입 할 수없는 이유가 Resource
있습니까? JavaEE WebSockets 내에서 지원되지 않습니까? Wildfly 8.1에 배포하고 있으며 내 애플리케이션은 WebSocket 구현 클래스 만있는 간단한 WAR입니다.
특정 CDI bean을 사용하는 JMS 주입에 몇 가지 문제가있는 것으로 보입니다. @javax.inject.Singleton
또는 을 사용하여 주사를 맞출 수있었습니다 @javax.ejb.Stateless
. @Named
두 경우 모두 주석을 제거했습니다 . 나는 주입을 테스트하지 않았습니다 Queue
.ConnectionFactory
WebSocket 클래스 만있는 간단한 웹 프로젝트로 최신 Glassfish 4 프로모션 빌드로 테스트했습니다.
@Stateless
@ServerEndpoint("/hello")
public class WsTest implements Serializable {
private static final Logger LOG = Logger.getLogger(WsTest.class.getName());
@Resource(mappedName = "java:comp/DefaultJMSConnectionFactory")
private ConnectionFactory connectionFactory = null;
@OnOpen
public void onOpen(Session session) throws IOException {
LOG.log(Level.INFO, "onOpen {0}", connectionFactory);
session.getBasicRemote().sendText("onOpen");
}
@OnMessage
public String echo(String message) {
LOG.log(Level.INFO, "onMessage({0}) {1}", new Object[]{message, connectionFactory});
return message + " (from your server)";
}
@OnError
public void onError(Throwable t) {
LOG.log(Level.INFO, "onError {0}", connectionFactory);
}
@OnClose
public void onClose(Session session) {
LOG.log(Level.INFO, "onClose {0}", connectionFactory);
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다