How to access JNDI data source defined in weblogic 10.3.6

前端 未结 3 1583
梦毁少年i
梦毁少年i 2021-01-18 00:32

I have created a JNDI data-source using my weblogic console but I am not able to access the object from my web application. Below are the details

In weblogic 10.3.6,

3条回答
  •  遇见更好的自我
    2021-01-18 01:08

    The same solution for Weblogic 12c would be

    add the below dependency to your pom.xml.. create a variable with current middleware home value ${oracleMiddlewareHome}, then...

    
            weblogic
            webservices
            12.1.3
            system
            
                ${oracleMiddlewareHome}/wlserver/server/lib/weblogic.jar
            
        
    

    Now use the below code :

     Hashtable h = new Hashtable(7);
    h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    h.put(Context.PROVIDER_URL, "t3://localhost:7001");//add ur url
    h.put(Context.SECURITY_PRINCIPAL, "weblogic");//add username
    h.put(Context.SECURITY_CREDENTIALS, "welcome1");//add password
    
        Bundle bundle;
        try {
            InitialContext ctx = new InitialContext(h);
           DataSource dataSource = ((DataSource) ctx.lookup("jdbc/ContextBindingDS"));
            bundle = (Bundle) ctx.lookup(BUNDLE_JNDI_NAME);
    
    
        } catch (NamingException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }catch (Exception e){
            e.printStackTrace();
        }
    

提交回复
热议问题