JNDI “Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory”

后端 未结 4 717
余生分开走
余生分开走 2021-01-12 13:05

I\'m using JBoss Server for EJB And I need JNDI in console app to get reference of session bean, console app code looks like this

import java.util.Properties         


        
4条回答
  •  既然无缘
    2021-01-12 13:45

    You can use following context to connect. I have tried and tested to set up this.

    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.NamingException;
    
    
    public class Program {
    
        public static void main(String[] args) throws NamingException {
          Properties jndiProps = new Properties();
        jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,         
        "org.jboss.naming.remote.client.InitialContextFactory");
        jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");
        jndiProps.put(Context.SECURITY_PRINCIPAL, "testuser");
        jndiProps.put(Context.SECURITY_CREDENTIALS, "testpassword");
        jndiProps.put("jboss.naming.client.ejb.context", true);
        Context ctx = new InitialContext(jndiProps);
        }
    
    }
    

    Then i got this error

    JBREM000200: Remote connection failed: javax.security.sasl.SaslException: 
    Authentication failed: all available authentication mechanisms failed - Could 
    not register a EJB receiver for connection to remote://localhost:4447  
    java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication 
    failed: all available authentication mechanisms failed.
    

    Then i added the user using add-user.sh.

    enter image description here

    Successful Handshake message came.

提交回复
热议问题