我試圖將jboss 7.1.1 final與三層體系結構方法連接起來,在我的業務層中保持連接邏輯並從此訪問此業務層我的表示層。但它是拋出以下異常無法在三層體系結構中實例化類:org.jboss.naming.remote.client.InitialContextFactory
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;
}
}
我檢查是否有遺漏,但它的罰款,因爲它是在單個程序集中運行,但問題是當我嘗試將這個整體邏輯組合在一個程序集中,並嘗試在其他程序中添加此打包程序集。 –