綁定jndi並載入資料來源_JNDI

來源:互聯網
上載者:User
   public Connection getConnection()        throws SQLException    {        Connection conn;        Context context = getContext();        DataSource dataSource = (DataSource)context.lookup(SystemProperty.getProperty("datasource"));        conn = dataSource.getConnection();        return conn;        Exception ex;        ex;        Debug.error(ex);        throw new ConfigException("Get Connection Error:" + ex.getMessage());    }    public Context getContext()        throws NamingException    {        if(context != null)        {            return context;        } else        {            Hashtable props = new Hashtable();            props.put("java.naming.factory.initial", SystemProperty.getProperty("java.naming.factory.initial"));            props.put("java.naming.provider.url", SystemProperty.getProperty("java.naming.provider.url"));            props.put("java.naming.security.principal", SystemProperty.getProperty("java.naming.security.principal"));            props.put("java.naming.security.credentials", SystemProperty.getProperty("java.naming.security.credentials"));            context = new InitialContext(props);            return context;        }    }

設定 InitialContext 的 JNDI 環境屬性 使用上下文尋找已命名物件 使用已命名物件擷取對象引用 關閉上下文。

附上設定檔:

#系統設定檔system.config=com.corp.frame.core.base.defaultdriver.DefaultConfigDriver#system.config=com.corp.frame.core.base.defaultdriver.DefaultConfigDriver_SampleContextsystem.cache=truesystem.debug=true# jeusjava.naming.factory.initial=jeus.jndi.JEUSContextFactoryjava.naming.provider.url=localhost:9736java.naming.security.principal=administratorjava.naming.security.credentials=11111111# tomcat#java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory#java.naming.provider.url=jnp://localhost:8088#java.naming.security.principal=admin#java.naming.security.credentials=#Weblogic#java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory   #java.naming.provider.url=t3://localhost:7001#java.naming.security.principal=weblogic#java.naming.security.credentials=weblogicdatabase.cutpageByProcude=false#for tomacat#datasource=java:comp/env/jdbc/stpt#for jeusdatasource=jdbc/stptworkflow=G:/work/stoa/dist/stoa/WEB-INF/workflow-config.xmluploadFileSavePath=D:/upload/stoa/uploadFilePath=D:/upload/stoa/countOfPage=10permission.command.data=falsepermission.command.data.validate.class=com.corp.frame.core.permission.data.DataPermissionValidateByInpermission.command.menu=falsepermission.command.submit=truepermission.command.link=truepermission.command.transaction=true


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.