简体   繁体   English

来自具有JNDI的其他IP服务器的spring.datasource.jndi-name

[英]spring.datasource.jndi-name from different ip server with JNDI

I am developed a service that use the DataSource from a local JNDI (Server where to live the service and the JNDI). 我开发了一项服务,该服务使用本地JNDI(服务所在的服务器和JNDI)中的数据源。

In Spring boot this information is declared like this: 在Spring Boot中,该信息的声明如下:

spring: datasource: 春天:数据源:
jndi-name: java:/comp/env/jdbc/MyLocalDB jndi名称:java:/ comp / env / jdbc / MyLocalDB

I want to know if is possible to do something like this: 我想知道是否可以做这样的事情:

spring: datasource: 春天:数据源:
jndi-name: java:192.168.0.1:8080/comp/env/jdbc/MyLocalDB jndi名称:java:192.168.0.1:8080 / comp / env / jdbc / MyLocalDB

Thanks 谢谢

JNDI is an API to access directories. JNDI是用于访问目录的API。 Application servers include directories to maintain information of the applications, the datasources and the EJB beans. 应用程序服务器包括用于维护应用程序,数据源和EJB Bean信息的目录。 JNDI can be used to access other types of directories. JNDI可用于访问其他类型的目录。 For instance, it can be used to access user information on Active Directoy and LDAP directory servers. 例如,它可以用于访问Active Directoy和LDAP目录服务器上的用户信息。

You can create client programs that access these JNDI directories and obtain data such as configuration data and RMI remote references to invoke EJB beans. 您可以创建访问这些JNDI目录的客户端程序,并获取诸如配置数据和RMI远程引用之类的数据以调用EJB bean。

Accessing remote JNDI directories 访问远程JNDI目录

If you are creating a client program, you can define an InitialContext describing the JNDI directory your program will use. 如果要创建客户端程序,则可以定义一个InitialContext描述程序将使用的JNDI目录。 You must define a Hashtable with the configuration, defining a Context.PROVIDER_URL and create the InitialContext . 您必须使用配置定义一个Hashtable ,定义一个Context.PROVIDER_URL并创建InitialContext

For instance, you can create a program that access information in an LDAP directory . 例如,您可以创建一个程序来访问LDAP目录中的信息

// 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

Depending on the library you use, you can define a configuration file describing the JNDI remote host. 根据您使用的库,您可以定义一个描述JNDI远程主机的配置文件。 For instance, for the JBoss EJB Client library , you can define a jboss-ejb-client.properties file. 例如,对于JBoss EJB客户端库 ,您可以定义jboss-ejb-client.properties文件。 Glassfish uses a jndi.properties file . Glassfish使用jndi.properties文件

Accessing remote resources 访问远程资源

A resource is data (eg an image, audio, or text) that a program needs to access independently of the location of the program code. 资源是程序需要独立于程序代码位置访问的数据(例如图像,音频或文本)。 You can use the JNDI API or the @Resource annotation to access the information. 您可以使用JNDI API或@Resource批注来访问信息。

For instance, you can use the API to ask for data of users in an LDAP directory. 例如,您可以使用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);
}

Accessing remote EJBs 访问远程EJB

You can access EJBs with remote interfaces located in other VMs . 您可以使用位于其他VM中的远程接口访问EJB On the one hand, you must create the EJBs using CORBA-style remote interfaces and register the EJBs in the java: namespace in the server. 一方面,您必须使用CORBA样式的远程接口创建EJB,并在服务器的java:命名空间中注册EJB。 On the other hand, the applications can use a corbaname URL to access these beans. 另一方面,应用程序可以使用corbaname URL来访问这些bean。

In Websphere/Liberty, if you define an EJB bound to: 在Websphere / Liberty中,如果您定义绑定到以下对象的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

You can access remotely the EJB using RMI-IIOP (to invoke methods) 您可以使用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

Detailed configuration of these remote EJBs may vary from one application server to another. 这些远程EJB的详细配置可能因一台应用程序服务器而异。 If you use Glassfish, you can check the documentation . 如果您使用Glassfish,则可以查看文档 There is an example in the Oracle blogs . Oracle博客中有一个示例

If you configure a cluster, there are many other options to access the remote resources using the names of the nodes in the cluster. 如果配置群集,则还有许多其他选项可使用群集中节点的名称来访问远程资源

Accessing a remote Datasources 访问远程数据源

Datasources defined in a server cannot be accessed remotely. 服务器中定义的数据源无法远程访问。 If you want to keep the configuration of the datasources in the JNDI directory, you can solutions define a custom class that implements the DataSource interface . 如果要将数据源的配置保留在JNDI目录中,则可以解决方案定义一个实现DataSource接口自定义类 A client can obtain the datasource configuration from the server and create a local database connection using that connection. 客户端可以从服务器获取数据源配置,并使用该连接创建本地数据库连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DataSource的可移植JNDI名称 - Portable JNDI name for DataSource 以编程方式为Spring创建JNDI DataSource - Programmatically creating a JNDI DataSource for Spring Spring Boot - 来自 JNDI 的数据源:NoInitialContextException:需要在环境或系统属性中指定类名 - Spring Boot - DataSource from JNDI: NoInitialContextException: Need to specify class name in environment or system property 使用 JNDI 配置数据源使用外部 Tomcat 9 服务器:Spring Boot - Configure DataSource Using JNDI Using external Tomcat 9 Server: Spring Boot 春天,通过具有远程JBoss Server的JNDI配置数据源 - Spring, configure the DataSource through JNDI having remote JBoss Server 从Spring application访问Web / App Server中定义的JNDI数据源Context xml / Junit测试用例 - Accessing JNDI datasource defined in Web/App Server from Spring applicationContext xml / Junit Test cases 关闭 Spring 应用程序会使数据源的 JNDI 名称脱离 jdbc 上下文 - Shutting down Spring application makes JNDI name for datasource go away from jdbc context 在Spring应用程序中从JBOSS 4.2.3配置JNDI数据源 - configuring a JNDI Datasource from JBOSS 4.2.3 in a Spring application JNDI找不到SQLServer的数据源 - JNDI not to find DataSource from SQLServer 如何从 IBM WebSphere 9 在 Spring Boot 中获取 JNDI 数据源 - How to get JNDI datasource in Spring Boot from IBM WebSphere 9
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM