failed:javax.naming.NameNotFoundException: QueueConnectionFactory
hi all
I have the problem how to solve this problem? when i was lookup through jndiname it was error but i declared it in a descriptor.
Error :
init:
deps-jar:
compile-single:
run-single:
Jndi lookup failed:javax.naming.NameNotFoundException: QueueConnectionFactory not found
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)
Here is the code...
That is Main....
public static void main(String[] args) {
Context jndiContext = null;
ConnectionFactory connectionfactory = null;
Connection connection = null;
Session session = null;
Destination destination = null;
MessageProducer messageProducer = null;
TextMessage message = null;
final int NUM_MSGS = 3;
try{
jndiContext = new InitialContext();
}catch(NamingException ex){
System.err.println("Could not Create JNDI.");
System.exit(1);
}
try
{
connectionfactory = (ConnectionFactory)jndiContext.lookup("jms/QueueConnectionFactory");
destination = (Queue)jndiContext.lookup("jms/SimpleMessageBean");
}catch(NamingException e){
System.err.println("Jndi lookup failed:" + e.toString());
System.exit(1);
}
try{
connection = connectionfactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageProducer = session.createProducer(destination);
message = session.createTextMessage();
for(int i=0; i < NUM_MSGS; i++){
message.setText("This is a message " + (i+1));
System.out.println("Sending message " + message.getText());
messageProducer.send(message);
}
}catch(javax.jms.JMSException e){
System.err.println("Exception occured: " + e.toString());
}finally
{
if(connection == null){
try{
connection.close();
}catch(JMSException e){
}
}
System.exit(0);
}
}
In Message Bean....
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "connectionFactoryJndiName", propertyValue="jms/QueueConnectionFactory")
})
public class SimpleMessage implements MessageListener {
public static final Logger logger = Logger.getLogger("SimpleMessage");
/** Creates a new instance of SimpleMessage */
public SimpleMessage() {
}
public void onMessage(Message message){
TextMessage msg = null;
try{
if(message instanceof TextMessage)
{
msg = (TextMessage)message;
logger.info("Message Bean: Message Received:" + msg.toString());
}else{
logger.warning("Wrong Type:" + msg.getClass().getName());
}
}catch(Throwable te){
te.printStackTrace();
}
}
In descriptor...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
<enterprise-beans>
<name>SimpleMessage</name>
<ejb>
<ejb-name>SimpleMessage</ejb-name>
<mdb-connection-factory>
<jndi-name>jms/QueueConnectionFactory</jndi-name>
</mdb-connection-factory>
</ejb>
<cmp-resource>
<jndi-name>jms/SimpleMessage</jndi-name>
</cmp-resource>
</enterprise-beans>
</sun-ejb-jar>
-
Thank you for reply..
Chris

