@Override public void addEnvironment(final ContextEnvironment environment) { normalize(environment); super.addEnvironment(environment); }
@Bean public WebServerFactoryCustomizer<TomcatServletWebServerFactory> webServerFactoryCustomizer() { return factory -> factory.addContextCustomizers( context -> { // 设置 JNDI 信息 ContextEnvironment environment = new ContextEnvironment(); environment.setName("jndi-name"); environment.setValue("My JNDI"); environment.setType(String.class.getName()); // 配置 Environment,等同于 <Environment/> 元素 context.getNamingResources().addEnvironment(environment); } ); }
/** * Add an environment entry for this web application. * * @param envName New environment entry name * @param type The type of the new environment entry * @param value The value of the new environment entry * @return the object name of the new environment entry * @throws MalformedObjectNameException if the object name was invalid */ public String addEnvironment(String envName, String type, String value) throws MalformedObjectNameException { NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource; if (nresources == null) { return null; } ContextEnvironment env = nresources.findEnvironment(envName); if (env != null) { throw new IllegalArgumentException( "Invalid environment name - already exists '" + envName + "'"); } env = new ContextEnvironment(); env.setName(envName); env.setType(type); env.setValue(value); nresources.addEnvironment(env); // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("ContextEnvironment"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env); return oname.toString(); }
/** * Add an environment entry for this web application. * * @param envName New environment entry name * @param type The type of the new environment entry * @param value The value of the new environment entry */ public String addEnvironment(String envName, String type, String value) throws MalformedObjectNameException { NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource; if (nresources == null) { return null; } ContextEnvironment env = nresources.findEnvironment(envName); if (env != null) { throw new IllegalArgumentException ("Invalid environment name - already exists '" + envName + "'"); } env = new ContextEnvironment(); env.setName(envName); env.setType(type); env.setValue(value); nresources.addEnvironment(env); // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("ContextEnvironment"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env); return (oname.toString()); }
/** * Add an environment entry for this web application. * * @param envName New environment entry name * @param type The type of the new environment entry * @param value The value of the new environment entry * @return the object name of the new environment entry * @throws MalformedObjectNameException if the object name was invalid */ public String addEnvironment(String envName, String type, String value) throws MalformedObjectNameException { NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource; if (nresources == null) { return null; } ContextEnvironment env = nresources.findEnvironment(envName); if (env != null) { throw new IllegalArgumentException( "Invalid environment name - already exists '" + envName + "'"); } env = new ContextEnvironment(); env.setName(envName); env.setType(type); env.setValue(value); nresources.addEnvironment(env); // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("ContextEnvironment"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env); return oname.toString(); }
context.getNamingResources().addEnvironment(resource);
naming.addEnvironment(environment);
resource.setLookupName(annotation.lookup()); context.getNamingResources().addEnvironment(resource);
resource.setLookupName(annotation.lookup()); context.getNamingResources().addEnvironment(resource);
context.getNamingResources().addEnvironment(environment);
context.getNamingResources().addEnvironment(environment);
context.getNamingResources().addEnvironment(environment);
ctx.getNamingResources().addEnvironment(env);