example3.java
来自「BEA WebLogic Server 8.1大全 = BEA webLogic」· Java 代码 · 共 77 行
JAVA
77 行
package com.wlsunleashed.jndi;
import javax.naming.Context;
import javax.naming.NamingException;
import weblogic.jndi.Environment;
/**
* This Example demonstrates the process of obtaining an InitialContext
* from the WebLogic server using WebLogic's Environment Object.
*
* No warranties, explicit or implied are made about this source code.
* This is provided as-is and
*
* @version 1.0
* @since July 2002
*/
public class Example3 {
/**
* Constant representing the Initial context factory to be used
*/
private static final String INITIAL_CONTEXT_FACTORY =
"weblogic.jndi.WLInitialContextFactory" ;
/**
* Constant representing the Provider URL
*/
private static final String PROVIDER_URL =
"t3://localhost:7001" ;
/**
* The main method is invoked when the class file is executed
* @param args : list of command line arguments
*/
public static void main(String[] args) {
Example3 object = new Example3();
try
{
Object boundObject = object.lookupObject(
"javax.transaction.UserTransaction");
System.out.println( "Object = " + boundObject );
}
catch (NamingException ne)
{
ne.printStackTrace();
}
}
/**
* lookupObject() returns the Object bound under the name given to this
* method as a parameter. The initial Context is obtained by using
* WebLogic's Environment object
* @param objectName The name of the binding
* @return Object
*/
private Object lookupObject(String objectName )
throws NamingException
{
System.out.println("looking up the initial context using " +
"WebLogic's Environment object ... " );
Environment env = new Environment();
env.setInitialContextFactory(INITIAL_CONTEXT_FACTORY);
env.setProviderUrl(PROVIDER_URL);
Context ctx = env.getInitialContext();
System.out.println( "Done. Got Initial Context = " +
ctx );
Object o = ctx.lookup(objectName);
ctx.close();
return o;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?