【发布时间】:2023-04-03 06:51:01
【问题描述】:
假设一个 CLI 或 Swing 接口客户端,如何通过 Glassfish 访问远程 Bean?由obtaining a reference toBeanManager?
示例代码:
Hashtable contextArgs = new Hashtable();
// First you must specify the context factory.
// This is how you choose between jboss implementation
// vs. an implementation from Sun or other vendors.
contextArgs.put( Context.INITIAL_CONTEXT_FACTORY, "com.jndiprovider.TheirContextFactory" );
// The next argument is the URL specifying where the data store is:
contextArgs.put( Context.PROVIDER_URL, "jndiprovider-database" );
// (You may also have to provide security credentials)
// Next you create the initial context
Context myCurrentContext = new InitialContext(contextArgs);
http://en.wikipedia.org/wiki/Java_Naming_and_Directory_Interface#Basic_lookup
因此,要让 CLI 应用程序访问正在运行的 glassfish 应用程序服务器,它会使用以下内容:
Context context = null;
try {
context = new InitialContext();
hello = (Hello) context.lookup("java:global/SalutationApp/SalutationApp-ejb/Hello");
hello.myRemoteMethod();
} catch (Exception e) {
e.printStackTrace();
}
仅使用指定的 URL 连接到特定的 glassfish 实例?如何建立连接?
【问题讨论】:
-
您是否考虑过用于 Swing 项目的应用程序客户端?这将允许您使用正常的@EJB 注入机制,尽管在您的主类静态变量中。
-
意志。那允许多个客户?
-
这就是 ejb-application-client 的目的。多个客户端,一分钟安装。自动球体配置等
-
从未见过选项。使用。 NetBeans。
标签: java jakarta-ee glassfish ejb cdi