Tomcat中JNDI数据源去掉java:/comp/env/

http://my.oschina.net/u/574870/blog/193782

摘要
Tomcat 中JNDI数据源去掉java:/comp/env/

 

Weblogictomcat的数据源配置不一样,每次在本地跑时都得修改数据源配置,

aaDs要改成java:/comp/env/aaDs

索性自己编译一个tomcat去掉前面的java:/comp/env/

过程如下.

Tomcat的源码下载及编译在此不再赘述,只说明修改的地方.

修改org.apache.naming.java.javaURLContextFactory getInitialContext方法,

true改为false

public Context getInitialContext(Hashtable environment)
        throws NamingException {
        if (ContextBindings.isThreadBound() || 
            (ContextBindings.isClassLoaderBound())) {
            // Redirect the request to the bound initial context
//true改为false
            return new SelectorContext(environment, false);
        } else {
            // If the thread is not bound, return a shared writable context
            if (initialContext == null)
                initialContext = new NamingContext(environment, MAIN);
            return initialContext;
        }
    }




修改org.apache.naming.SelectorContextparseName方法,

不判断initialContext直接返回name

protected String parseName(String name)
        throws NamingException {

        if ((!initialContext) && (name.startsWith(prefix))) {
            return (name.substring(prefixLength));
        } else {
		//不判断initialContext直接返回name
           // if (initialContext) {
                return (name);
          /*  } else {
                throw new NamingException
                    (sm.getString("selectorContext.noJavaUrl"));
            }*/
        }

}




修改org.apache.catalina.core. NamingContextListenerparseName方法,

直接取namingContext作为compCtx, envCtx不作叛断

private void createNamingContext()
        throws NamingException {

        // Creating the comp subcontext
//直接取namingContext作为compCtx, envCtx不作叛断
      //  if (container instanceof Server) {
            compCtx = namingContext;
            envCtx = namingContext;
      /*  } else {
            compCtx = namingContext.createSubcontext("comp");
            envCtx = compCtx.createSubcontext("env");
        }*/

        int i;

        if (log.isDebugEnabled())
            log.debug("Creating JNDI naming context");

        if (namingResources == null) {
            namingResources = new NamingResources();
            namingResources.setContainer(container);
        }





你可能感兴趣的:(Tomcat中JNDI数据源去掉java:/comp/env/)