- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我开发了一项服务,该服务使用本地 JNDI 中的数据源(服务和 JNDI 所在的服务器)。
在 Spring boot 中,此信息声明如下:
spring: datasource:
jndi-name: java:/comp/env/jdbc/MyLocalDB
我想知道是否可以做这样的事情:
spring: datasource:
jndi-name: java:192.168.0.1:8080/comp/env/jdbc/MyLocalDB
谢谢
最佳答案
JNDI 是访问目录的 API。应用程序服务器包括用于维护应用程序、数据源和 EJB bean 信息的目录。 JNDI 可用于访问其他类型的目录。例如,它可用于访问 Active Directory 和 LDAP 目录服务器上的用户信息。
您可以创建访问这些 JNDI 目录并获取配置数据和 RMI 远程引用等数据的客户端程序来调用 EJB bean。
访问远程 JNDI 目录
如果您正在创建客户端程序,您可以define an InitialContext
描述您的程序将使用的 JNDI 目录。您必须使用配置定义 Hashtable
,定义 Context.PROVIDER_URL
并创建 InitialContext
。
例如,您可以创建一个程序 access information in an LDAP directory .
// Set up the environment for creating the initial context
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
// ... do something useful with ctx
根据您使用的库,您可以定义描述 JNDI 远程主机的配置文件。例如,对于 JBoss EJB Client library ,您可以定义一个jboss-ejb-client.properties
文件。 Glassfish 使用 jndi.properties
file .
访问远程资源
资源是程序需要独立于程序代码的位置访问的数据(例如图像、音频或文本)。您可以使用 JNDI API 或 @Resource
annotation访问信息。
例如,您可以使用 API 来请求 LDAP 目录中的用户数据。
try {
// Create the initial directory context
DirContext ctx = new InitialDirContext(env);
// Ask for all attributes of the object
Attributes attrs = ctx.getAttributes("cn=Ted Geisel, ou=People");
// Find the surname attribute ("sn") and print it
System.out.println("sn: " + attrs.get("sn").get());
} catch (NamingException e) {
System.err.println("Problem getting attribute:" + e);
}
访问远程 EJB
您可以access EJBs with remote interfaces located in other VMs 。一方面,您必须使用 CORBA 样式的远程接口(interface)创建 EJB,并在服务器的 java:
命名空间中注册 EJB。另一方面,应用程序可以使用 corbaname
URL 来访问这些 bean。
在 Websphere/Liberty 中,如果您定义绑定(bind)到的 EJB:
java:global/ExampleApp/ExampleModule/ExampleBean!com.ibm.example.ExampleRemoteInterface
java:app/ExampleModule/ExampleBean!com.ibm.example.ExampleRemoteInterface
java:module/ExampleBean!com.ibm.example.ExampleRemoteInterface
您可以使用 RMI-IIOP 远程访问 EJB(以调用方法)
corbaname::test.ibm.com:2809#ejb/global/ExampleApp/ExampleModule/ExampleHomeBean!com.ibm.example.ExampleEJBHome
corbaname:rir:#ejb/global/ExampleApp/ExampleModule/ExampleHomeBean!com.ibm.example.ExampleEJBHome
这些远程 EJB 的详细配置可能因应用程序服务器而异。如果您使用Glassfish,您可以检查documentation 。有一个example in the Oracle blogs .
如果配置集群的话,还有很多其他options to access the remote resources使用集群中节点的名称。
访问远程数据源
无法远程访问服务器中定义的数据源。如果您想将数据源的配置保留在 JNDI 目录中,您可以解决方案定义 custom class that implements the DataSource
interface 。客户端可以从服务器获取数据源配置并使用该连接创建本地数据库连接。
关于java - spring.datasource.jndi-name 来自具有 JNDI 的不同 ip 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45923971/
我是 JNDI 的新手,我阅读了 oracle 的在线资料: http://docs.oracle.com/javase/jndi/tutorial/getStarted/overview/index
什么是JNDI? 它的基本用途是什么? 什么时候使用? 最佳答案 What is JNDI ? 它代表Java Naming and Directory Interface . What is its
我有完整的应用服务器背景,并考虑在 Jetty 等轻量级嵌入式服务器上运行应用。 我一直使用 JNDI 来查找连接池以查找数据库连接之类的东西,但我想知道这是否是轻量级案例的最佳方法。似乎如果我使用
您如何使用 JDBCRealm处理servlet 中的用户身份验证和授权?我能找到的唯一示例是在 web.xml 中创建数据源(例如 Authentication against database u
命名和目录 (JNDI) - 使用 JNDI 的陷阱是什么 最佳答案 这个问题有点含糊,但这里有几点需要考虑并且与 JNDI 相关。 JNDI 的好处是对象创建与对象查找分离 在 JDNI 中直接查找
在 Wildfly 9 中显示注册的 JNDI 名称的正确方法是什么? 对于旧版本,可以使用 /subsystem=naming:jndi-view ,但它似乎不再起作用。在域模式下运行时。 感谢帮助
我有两个 JBoss 服务器,JbossA 和 JbossB。每个都有自己的 JNDI。现在我在 JbossA 上有一个名为 jms/Client 的 JMS,在 JbossB 上有一个名为 jms/
这是我的“hibernate.cfg.xml”,我正在尝试连接到我的本地主机(postgres),但我不确定我是否输入了参数值(例如连接 url 或其他) : org.hiber
是否可以通过 JNDI 访问 Wildfly 属性(在 standalone.xml 中定义)? 喜欢: ... 并在java中阅读它: @Resource(lo
第126章OSGI Enterprise Release 5 specification提到兼容性: "Support the traditional JNDI programming model u
import org.apache.catalina.Context; import org.apache.catalina.deploy.ContextResource; import org.ap
在我们的项目中,我们使用 websphere liberty 服务器和 IBM MQ 作为消息服务器。我们在云中移动。我们想用 AWS SQS 替换 IBM MQ。在 server.xml 中,我们有
似乎每个人都说您应该使用 Tomcat 的 JNDI 上下文来管理您的 JDBC 连接和驱动程序等等。在阅读了文档之后,我理解了平局。但是,如果您使用它,您的应用程序必须从现在开始一直使用 Tomca
我正在 JBoss7.1.1 应用程序服务器上部署我的 MDB (EJB3.1)。当我使用@Resource进行数据源注入(inject)时,我使用全局JNDI引用名称(ENC +本地JNDI引用名称
使用 JBoss eap 6.4.12 出现错误: Error looking up ${email.jndi.lookup.binding} in JNDI 在我的 java 类中映射此 JNDI
使用com.sun.jndi.fscontext.RefFSContextFactory基于文件的 JNDI 上下文工厂,它似乎只允许在您指定的位置有 1 个绑定(bind)文件。例如 Hashtab
这是我的persistence.xml: org.hibernate.ejb.HibernatePersistence jdbc/abcDS 这是来自 src/test
我已经为我的模块之一运行了强化扫描,我已经收到了 动态代码评估:JNDI 引用注入(inject)漏洞问题 显示在下一行 lookup(dataSource) 数据源是动态的。我应该怎么做才能防止这种
我有 EJB 3.1 中的 EJB,我试图将其部署在 JBoss EAP 6 中,但是当我启动服务器时。它在 JNDI 名称中附加版本号,如下所示。 18:27:57,068 INFO [org.j
我有一个测试,它成功地使用嵌入式 glassfish 来测试 JCA 的部署。 但是,与已经在使用端口 3700 的 GlassFish 2.1 的运行版本存在冲突。 如何将嵌入的 GlassFish
我是一名优秀的程序员,十分优秀!