How to lookup JNDI resources on WebLogic?

前端 未结 4 606
刺人心
刺人心 2020-11-30 08:27

I deployed a legacy application on WebLogic 11g. The application has the following code:

 Context context = new InitialContext();
 dataSource = (javax.sql.Da         


        
4条回答
  •  萌比男神i
    2020-11-30 08:37

    You should be able to simply do this:

    Context context = new InitialContext();
    dataSource = (javax.sql.DataSource) context.lookup("jdbc/myDataSource");
    

    If you are looking it up from a remote destination you need to use the WL initial context factory like this:

    Hashtable h = new Hashtable(7);
    h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    h.put(Context.PROVIDER_URL, pURL); //For example "t3://127.0.0.1:7001"
    h.put(Context.SECURITY_PRINCIPAL, pUsername);
    h.put(Context.SECURITY_CREDENTIALS, pPassword);
    
    InitialContext context = new InitialContext(h);
    dataSource = (javax.sql.DataSource) context.lookup("jdbc/myDataSource");
    

    weblogic.jndi.WLInitialContextFactory

提交回复
热议问题