Wildfly 8 - ejb客户端问题

时间:2014-06-19 23:48:01

标签: java-ee ejb client wildfly

我正在关注教程并且:

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

Wildfly在部署ejb时返回此信息:

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

我的客户尝试:

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();
    }
}

错误:

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(COMPILE SCOPE)

老实说不确定是什么问题:jndi名称,或者因为我从外部容器调用远程EJB,需要其他东西。

PS:EJB部署得很好

有任何输入吗?

TNX

1 个答案:

答案 0 :(得分:2)

我修改了:

    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

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