在远程上下文中创建数据源

时间:2014-01-22 14:42:56

标签: java-ee weblogic datasource jndi

我正在尝试在远程上下文中创建数据源,但是在远程上下文中绑定数据源时遇到错误; datasource不可序列化。

这是在本地上下文中创建数据源的示例: http://db.apache.org/derby/docs/10.1/publishedapi/org/apache/derby/jdbc/ClientDataSource.html

org.apache.derby.client.ClientDataSource dataSource = new org.apache.derby.client.ClientDataSource ();
dataSource.setServerName ("my_derby_database_server");
dataSource.setDatabaseName ("my_derby_database_name");
javax.naming.Context context = new javax.naming.InitialContext();
context.bind ("jdbc/my_datasource_name", dataSource);

但表演时:

org.apache.commons.dbcp.BasicDataSource dataSource = new org.apache.commons.dbcp.BasicDataSource();
dataSource.setServerName ("my_database_server");
dataSource.setDatabaseName ("my_database_name");
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    env.put(Context.PROVIDER_URL,URL);
    env.put(Context.SECURITY_PRINCIPAL,USER);
    env.put(Context.SECURITY_CREDENTIALS,PASS);
javax.naming.Context context = new javax.naming.InitialContext(env);
context.bind ("jdbc/my_datasource_name", dataSource);

我收到了错误:

javax.naming.ConfigurationException [Root exception is java.rmi.MarshalException: failed to marshal bind(Ljava.lang.String;Ljava.lang.Object;Ljava.util.Hashtable;); nested exception is: 
java.io.NotSerializableException: org.apache.commons.dbcp.BasicDataSource]
at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:38)
at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:68)
at weblogic.jndi.internal.WLContextImpl.translateException(WLContextImpl.java:439)
at weblogic.jndi.internal.WLContextImpl.bind(WLContextImpl.java:415)
at javax.naming.InitialContext.bind(InitialContext.java:400)
at exploit.v2_Test.main(v2_Test.java:83)
Caused by: java.rmi.MarshalException: failed to marshal bind(Ljava.lang.String;Ljava.lang.Object;Ljava.util.Hashtable;); nested exception is: 
java.io.NotSerializableException: org.apache.commons.dbcp.BasicDataSource
at weblogic.rjvm.BasicOutboundRequest.marshalArgs(BasicOutboundRequest.java:90)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:342)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at weblogic.jndi.internal.ServerNamingNode_1030_WLStub.bind(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.bind(WLContextImpl.java:413)
... 2 more

0 个答案:

没有答案
相关问题