- - PR -
JBoss + EJB でlookupできない
1
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2006-08-03 18:21
皆様
お世話になってます。 JBoss導入の際に、コネクションプーリングの動作確認をしようとしたところ、 Context.lookupにて、バインドされているJNDI名が解決されません。 構成 jboss-4.0.3SP1 Eclipse3.1 + JBoss-IDEプラグイン Javaソース package hoge; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; import javax.sql.DataSource; public class EchoClient { public static Object lookup(String name, Class type) throws NamingException,SQLException { //DBへ接続(コネクション取得) // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); //直接DBにつなぐ //Connection conn = //DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521","hr", "password"); Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); props.put(Context.PROVIDER_URL, "jnp://localhost:1099"); InitialContext ctx = new InitialContext(props); ctx.lookup("OracleDS"); //コネクションプーリングVer DataSource ds = (DataSource)ctx.lookup("java:OracleDS"); Connection conn = ds.getConnection(); //ステートメントオブジェクト生成 Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery ("select * from employees"); conn.close(); rset.close(); stmt.close(); ResultSetMetaData rmeta = rset.getMetaData(); int columnCount = rmeta.getColumnCount(); String[] columnNames = new String[columnCount]; for(int i = 0; i < columnCount ; i++){ columnNames[i] = rmeta.getColumnName(i+1); } Object home = PortableRemoteObject.narrow(ctx.lookup(name), type); return home; } public static String sayEcho(String message) { try { EchoHome home = (EchoHome) lookup("ejb/Echo", EchoHome.class); Echo echo = home.create(); String result = echo.sayEcho(message); return result; } catch (Exception e) { e.printStackTrace(); return ""; } } public static void main(String[] args) throws Exception { String result = sayEcho("hello"); System.out.println(result); } } ソース抜粋 ctx.lookup("OracleDS"); //コネクションプーリングVer DataSource ds = (DataSource)ctx.lookup("java:OracleDS"); ここで落ちます。 JBoss起動時のログについては 18:14:43,906 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=OracleDS' to JNDI name 'java:OracleDS' OracleDSという名前でバインドされているはずなのですが、 javax.naming.NameNotFoundException: OracleDS not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:514) at org.jnp.server.NamingServer.getBinding(NamingServer.java:522) at org.jnp.server.NamingServer.getObject(NamingServer.java:528) at org.jnp.server.NamingServer.lookup(NamingServer.java:281) at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) at sun.rmi.transport.Transport$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Unknown Source) at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source) at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source) at sun.rmi.server.UnicastRef.invoke(Unknown Source) at org.jnp.server.NamingServer_Stub.lookup(Unknown Source) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572) at javax.naming.InitialContext.lookup(Unknown Source) at hoge.EchoClient.lookup(EchoClient.java:39) at hoge.EchoClient.sayEcho(EchoClient.java:67) at hoge.EchoClient.main(EchoClient.java:79) ちなみに、 C:\jboss-4.0.3SP1\server\default\deploy\oracle-ds.xml の内容は <datasources> <local-tx-datasource> <jndi-name>OracleDS</jndi-name> <connection-url>jdbc:oracle:thin:@localhost:1521</connection-url> <!-- Here are a couple of the possible OCI configurations. For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm <connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url> or <connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url> Clearly, its better to have TNS set up properly. --> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <user-name>hr</user-name> <password>password</password> <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool --> <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name--> <!-- Checks the Oracle error codes and messages for fatal errors --> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name> <!-- sql to call when connection is created <new-connection-sql>some arbitrary sql</new-connection-sql> --> <!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql> --> <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) --> <metadata> <type-mapping>Oracle9i</type-mapping> </metadata> </local-tx-datasource> </datasources> となってます。 バインドできているように見えて、lookup("OracleDS")がこける理由が分かりません。 ご回答よろしくお願いします。 |
1