ejb 远程调用
1,客户端代码:
package com.example.test; import java.util.Hashtable; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import com.example.HelloWorldRemote; //import cn.ejb.HelloWorldRemote; public class HelloWorldTest { public static void main(String[] args) { Properties jndiProperties = new Properties(); // Hashtable jndiProperties = new Hashtable(); jndiProperties.put("jboss.naming.client.ejb.context", true); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); //写这里不行!!! // jndiProperties.put(Context.SECURITY_PRINCIPAL, "testUser"); // jndiProperties.put(Context.SECURITY_CREDENTIALS, "12345678"); try { Context context = new InitialContext(jndiProperties); final String appName = ""; final String moduleName = "hello"; final String distinctName = ""; Object obj = context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/HelloWorld!com.example.HelloWorldRemote"); System.out.println(obj); HelloWorldRemote hwr = (HelloWorldRemote) obj; String say = hwr.hello( ); System.out.println(say); } catch (NamingException e) { e.printStackTrace(); } } }
2,src下的jboss-ejb-client.properties
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=211.100.75.242
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=testUser
remote.connection.default.password=12345678
3,用jboss\bin\add-user.sh 加个 applicationRealm
[userone@localhost bin]$ ./add-user.sh What type of user do you wish to add? a) Management User (mgmt-users.properties) b) Application User (application-users.properties) (a): b Enter the details of the new user to add. Realm (ApplicationRealm) : ApplicationRealm ---->> Careful Here . You need to type this or leave it blank . I filled an incorrect value here and things went wrong from there . Username : testuser Password : testpassword Re-enter Password : testpassword What roles do you want this user to belong to? (Please enter a comma separated list, or leave blank for none) : testrole About to add user 'testuser' for realm 'ApplicationRealm' Is this correct yes/no? yes Added user 'testuser' to file '/home/userone/jboss-as-7.1.0.Final/standalone/configuration/application-users.properties' Added user 'testuser' to file '/home/userone/jboss-as-7.1.0.Final/domain/configuration/application-users.properties' Added user 'testuser' with roles testrole to file '/home/userone/jboss-as-7.1.0.Final/standalone/configuration/application-roles.properties' Added user 'testuser' with roles testrole to file '/home/userone/jboss-as-7.1.0.Final/domain/configuration/application-roles.properties' . 大功告成了 参考: .http://stackoverflow.com/questions/19129836/javax-security-sasl-saslexception-authentic-failed-while-connecting-to-jboss-7 http://middlewaremagic.com/jboss/?p=1466 https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?