EJB下remote not bound 错误

阅读更多

EJB报错如下:

javax.naming.NameNotFoundException: remote 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 org.jnp.server.NamingServer.lookup(NamingServer.java:270) 
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:597) 
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305) 
at sun.rmi.transport.Transport$1.run(Transport.java:159) 
at java.security.AccessController.doPrivileged(Native Method) 
at sun.rmi.transport.Transport.serviceCall(Transport.java:155) 
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
at java.lang.Thread.run(Thread.java:619) 
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) 
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233) 
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142) 
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source) 
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667) 
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627) 
at javax.naming.InitialContext.lookup(InitialContext.java:392) 
at junit.test.PersionServiceTest.setUpBeforeClass(PersionServiceTest.java:22) 
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:597) 
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74) 
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50) 
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33) 
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) 
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) 

 

当然就算是初学者也知道,绑定不上远程!可到底是哪里绑定不上呢?可以一步步的测试!

先看三个文件:

远程接口文件:

package service.impl;
import java.util.List;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import service.PersionService;
import bean.Persion;
@Stateless
@Remote(PersionService.class)
public class PersoinServiceBean implements PersionService {
	@PersistenceContext(unitName = "golden")
	EntityManager en;
	public void delete(Integer persionid) {
		en.remove(en.getReference(Persion.class, persionid));
	}
	public Persion getPersion(Integer persionid) {
		return en.find(Persion.class, persionid);
	}
	@SuppressWarnings("unchecked")
	public List getPersions() {
		return en.createQuery("select * from Persion p").getResultList();
	}
	public void save(Persion persion) {
		en.persist(persion);
	}
	public void update(Persion persion) {
		en.merge(persion);
	}
}

 

连接池配置文件:persistence.xml(在项目SRC下的META-INF下)



	
		java:goldenDS
	

 

Jboss连接数据库配置文件,这里是用的是Mysql



	
		goldenDS
		
			jdbc:mysql://localhost:3306/golden?useUnicode=true&characterEncoding=utf-8
		
		com.mysql.jdbc.Driver
		root
		root
		
			org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
		
		
			mySQL
		
	

 

1.先看服务器是否连接上了数据库,启动服务器 连接到主页从 JMX Console 可以看到相应链接池的情况

 

2.看远程接口是否正确,去除管理对象

@PersistenceContext(unitName = "golden") EntityManager en;

 

这时通过测试看是否能得到远程的对象

如果远程无法绑定或相应的远程接口无法绑定,则一个可能是由于接口本身创建时错误,还有可能是接口实现类内部调用的对象出错!

本次错误就是因为调用的管理对象无法创建造成的!

首选是服务器配置文件的错误,连接字符串不正确,再者,persistence.xml一定要在META-INF下切这个文件名称全是小写!

你可能感兴趣的:(EJB,Java,junit,Eclipse,exception)