首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wildfly 8- ejb客户端问题

Wildfly 8- ejb客户端问题
EN

Stack Overflow用户
提问于 2014-06-19 23:48:00
回答 1查看 3.8K关注 0票数 1

我正在学习一个教程,并且:

将一个ejb部署到Wildfly 8 ->检查

Wildfly在部署ejb时返回此值:

代码语言:javascript
复制
java:global/ejb/EmployeeManagementServiceImpl!staffmanagement.EmployeeManagementService
java:app/ejb/EmployeeManagementServiceImpl!staffmanagement.EmployeeManagementService
java:module/EmployeeManagementServiceImpl!staffmanagement.EmployeeManagementService
java:jboss/exported/ejb/EmployeeManagementServiceImpl!staffmanagement.EmployeeManagementService
java:global/ejb/EmployeeManagementServiceImpl
java:app/ejb/EmployeeManagementServiceImpl
java:module/EmployeeManagementServiceImpl

我的当事人试图:

代码语言:javascript
复制
public class ClientApplicationTest {

public static void main( String[] args ) {
    System.out.println( "Hello World ClientApplicationTest!" );
    try {
        Context jndi = new InitialContext();
        String name = "java:module/EmployeeManagementServiceImpl";
        EmployeeManagementService service = (EmployeeManagementService) jndi.lookup(name);

        List<Employee> employees = service.getAllEmployees();
        for(Employee employee :employees ) {
            System.out.println(employee);
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }
}

错误:

代码语言:javascript
复制
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at j2ee.staffmanagement.client.ClientApplicationTest.main(ClientApplicationTest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

我向客户机添加了以下库(除了ejb本身):/Library/WildFly/modules/system/layers/base/org/jboss/as/appclient/main/wildfly-appclient-8.1.0.Final.jar (编译范围)

老实说,不知道哪里出了问题: jndi名称,或者因为我从外部容器调用远程EJB,需要一些其他的东西。

PS: EJB部署良好

有什么输入吗?

Tnx

EN

回答 1

Stack Overflow用户

发布于 2014-06-20 05:13:30

我修改了:

代码语言:javascript
复制
    Properties jndiProperties = new Properties();
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");

    try {
        Context jndi = new InitialContext(jndiProperties);
        String appName = "";
        String moduleName = "staff";
        String distinctName = "";
        String beanName = "EmployeeManagementServiceImpl";
        String interfaceFullName = "staffmanagement.EmployeeManagementService";
        String jndiName = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + interfaceFullName;
        //ejb:{app-Name}/{module-Name}/{distinct-Name}/{bean-Name}!{fullPath-remote-Interface}
        EmployeeManagementService service = (EmployeeManagementService) jndi.lookup(jndiName);
        ...

并在类路径中添加了文件: jboss-ejb-client.properties

代码语言:javascript
复制
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost 
remote.connection.default.port = 8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24317960

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档