jndi.properties
密钥的可能属性名称是什么?我找不到关于所有可能的关键名称的文档。
如何为jndi.properties输出主体,凭证和远程键/值对?
-run:
[java] Sep 12, 2014 6:36:43 PM dur.bounceme.net.remotelookup.RemoteLookup run
[java] INFO: java.naming.factory.initial com.sun.enterprise.naming.impl.SerialInitContextFactory
[java] Sep 12, 2014 6:36:43 PM dur.bounceme.net.remotelookup.RemoteLookup run
[java] INFO: java.naming.factory.url.pkgs com.sun.enterprise.naming
[java] Sep 12, 2014 6:36:43 PM dur.bounceme.net.remotelookup.RemoteLookup run
[java] INFO: java.naming.factory.state com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
run:
BUILD SUCCESSFUL
Total time: 13 seconds
thufir@dur:~/NetBeansProjects/LegacyEJB$
thufir@dur:~/NetBeansProjects/LegacyEJB$ cat src/java/jndi.properties
java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=server.local\:1199
java.naming.security.principal=user
java.naming.security.credentials=password
remote=net.bounceme.ix.Foo
thufir@dur:~/NetBeansProjects/LegacyEJB$
可以看出,并非所有的键/值对都在输出。为什么?
对于“远程”名称和值,是否应该放在不同的属性文件中?
主要课程:
package dur.bounceme.net.remotelookup;
import java.util.Enumeration;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class RemoteLookup {
private static final Logger log = Logger.getLogger(RemoteLookup.class.getName());
private final MyProps p = new MyProps();
public static void main(String... args) {
try {
new RemoteLookup().run();
} catch (NamingException ex) {
Logger.getLogger(RemoteLookup.class.getName()).log(Level.SEVERE, ex.getExplanation(), ex);
}
}
private void run() throws NamingException {
Properties jndi = p.getJNDI();
Enumeration e = jndi.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String val = jndi.getProperty(key);
log.info(key + "\t" + val);
}
Context ic = new InitialContext();
// MyRemote mr = (MyRemote) ic.lookup("java:comp/env/ejb/Foo"); //
}
}
读取属性文件,已经过去了:
package dur.bounceme.net.remotelookup;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
public class MyProps {
private static final Logger log = Logger.getLogger(MyProps.class.getName());
private final Properties jndi = new Properties();
public MyProps() {
try {
loadJNDI();
String name = jndi.getProperty("name");
} catch (IOException ex) {
Logger.getLogger(MyProps.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Properties getJNDI() {
return jndi;
}
private void loadJNDI() throws IOException {
jndi.load(MyProps.class.getResourceAsStream("/jndi.properties"));
}
}
更重要的是,键的名称应该是什么?
----------------------------------------------- -------编辑-------------------------
java.naming.factory.initial的= TO_BE_CHANGED_BY_USER java.naming.factory.object = TO_BE_CHANGED_BY_USER java.naming.factory.state = TO_BE_CHANGED_BY_USER java.naming.factory.control = TO_BE_CHANGED_BY_USER java.naming.factory.url.pkgs = TO_BE_CHANGED_BY_USER java.naming.provider.url的= TO_BE_CHANGED_BY_USER java.naming.dns.url = TO_BE_CHANGED_BY_USER
从: