我正在尝试将 jboss 7.1.1 final 与三层架构方法连接起来,将连接逻辑保留在我的业务层中,并从我的表示层访问这个业务层。但它抛出以下异常
Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory.
如果我将 jboss 连接逻辑保留在同一表示层中,它工作正常。
以下是我在业务逻辑中的代码。
public static void Connect()
{
try
{
javax.naming.Context context = null;
ConnectionFactory connectionFactory;
Connection connection;
Session session;
String topicName = "jms/topic/TestedTopic";
Destination dest = null;
MessageConsumer consumer = null;
TextListener listener = null;
java.util.Properties jndiProps = new java.util.Properties();
jndiProps.put(Context.__Fields.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.__Fields.PROVIDER_URL, "remote://10.1.7.149:4447");
jndiProps.put(Context.__Fields.SECURITY_PRINCIPAL, "admin");
jndiProps.put(Context.__Fields.SECURITY_CREDENTIALS, "admin123");
jndiProps.put("jboss.naming.client.ejb.context", true);
context = new InitialContext(jndiProps);
connectionFactory = (ConnectionFactory)context.lookup("jms/RemoteConnectionFactory");
connection = connectionFactory.createConnection();
dest = (Destination)context.lookup(topicName);
session = connection.createSession(false, Session.__Fields.AUTO_ACKNOWLEDGE);
consumer = session.createConsumer(dest);
listener = new TextListener();
consumer.setMessageListener(listener);
connection.start();
}
catch (Exception)
{
//throw;
}
}