Ai galera, to querendo aprender ejb3…
Peguei um tutorial na net ele parece bom para caramba, ensina passo-a-passo como desenvolver e fazer o deploy usando o JBOSS…
Contudo quando tento rodar o meu cliente, é lançada um exception
javax.naming.NameNotFoundException: com.service.UsuarioService not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.service.ServiceLocator.get(Unknown Source)
at com.testes.TestUsuario.main(TestUsuario.java:9)
java.lang.NullPointerException
at com.testes.TestUsuario.main(TestUsuario.java:10)
Abaixo segue meus codigos
package com.model.ejb.session;
import java.rmi.RemoteException;
import javax.ejb.Stateless;
import com.service.UsuarioService;
@Stateless
public class UsuarioServiceBean implements UsuarioService {
public String getMessage() throws RemoteException {
return "Hello World";
}
}
package com.service;
import java.rmi.RemoteException;
import javax.ejb.Remote;
@Remote
public interface UsuarioService {
public String getMessage() throws RemoteException;
}
package com.service;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ServiceLocator {
private static ServiceLocator locator = null;
private InitialContext initialContext;
@SuppressWarnings("unchecked")
private ServiceLocator() {
try {
Hashtable t = new Hashtable();
t.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
t.put(Context.PROVIDER_URL,"localhost");
t.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
initialContext = new InitialContext(t);
} catch (Exception exc) {
exc.printStackTrace();
}
}
public static ServiceLocator getInstance() {
if(ServiceLocator.locator == null) {
ServiceLocator.locator = new ServiceLocator();
}
return locator;
}
protected Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
public Object get(String jndiName) throws Exception {
try {
Object result = null;
result = initialContext.lookup(jndiName);
if(result == null) {
throw new NamingException();
}
return result;
} catch(NamingException e) {
e.printStackTrace();
}
return null;
}
}
package com.testes;
import com.service.ServiceLocator;
import com.service.UsuarioService;
public class TestUsuario {
public static void main(String[] args) {
try {
UsuarioService usuario = (UsuarioService) ServiceLocator.getInstance().get(UsuarioService.class.getName());
System.out.println(usuario.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Vlw galera, abraço!!!
