我做的一个EJB3.0的一个例子,总是在报ejb3 javax.naming.NameNotFoundException这个错,说PostgresDS not bound请问高手指点指点。
我的数据源配置文件是:
<datasources>
<local-tx-datasource>
<jndi-name>PostgresDS</jndi-name>
<connection-url>jdbc:postgresql://127.0.0.1/TESTEJB</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>1111</user-name>
<password>1111</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<metadata>
<type-mapping>PostgreSQL 8.2</type-mapping>
</metadata>
<use-java-context>false</use-java-context>
</local-tx-datasource>
</datasources>
persistence.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="postgresDB" transaction-type="JTA">
<jta-data-source>java:/PostgresDS</jta-data-source>
</persistence-unit>
</persistence>
entitybean:package entity;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;@Entity
@Table(name = "users", schema = "public", uniqueConstraints = {})
public class Users implements java.io.Serializable { private Integer id;
private String name;
/** default constructor */
public Users() {
}
/** full constructor */
public Users(Integer id, String name) {
this.id = id;
this.name = name;
}
// Property accessors
@Id
@Column(name = "id", unique = true, nullable = false, insertable = true, updatable = true)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
我的数据源配置文件是:
<datasources>
<local-tx-datasource>
<jndi-name>PostgresDS</jndi-name>
<connection-url>jdbc:postgresql://127.0.0.1/TESTEJB</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>1111</user-name>
<password>1111</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<metadata>
<type-mapping>PostgreSQL 8.2</type-mapping>
</metadata>
<use-java-context>false</use-java-context>
</local-tx-datasource>
</datasources>
persistence.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="postgresDB" transaction-type="JTA">
<jta-data-source>java:/PostgresDS</jta-data-source>
</persistence-unit>
</persistence>
entitybean:package entity;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;@Entity
@Table(name = "users", schema = "public", uniqueConstraints = {})
public class Users implements java.io.Serializable { private Integer id;
private String name;
/** default constructor */
public Users() {
}
/** full constructor */
public Users(Integer id, String name) {
this.id = id;
this.name = name;
}
// Property accessors
@Id
@Column(name = "id", unique = true, nullable = false, insertable = true, updatable = true)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
楼主【mj198523】截止到2008-07-29 17:53:10的历史汇总数据(不包括此帖):
发帖的总数量:10 发帖的总分数:250 每贴平均分数:25
回帖的总数量:5 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:1 结贴的总分数:20
无满意结贴数:0 无满意结贴分:0
未结的帖子数:9 未结的总分数:230
结贴的百分比:10.00 % 结分的百分比:8.00 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=mj198523
>10:49:27,781 INFO [Ejb3Deployment] EJB3 deployment time took: 47
>10:49:27,781 INFO [JmxKernelAbstraction] installing MBean: persistence.units:jar=EJB.jar,unitName=PostgresDS with dependencies:
>10:49:27,781 INFO [JmxKernelAbstraction] jboss.jca:name=PostgresDS,service=ManagedConnectionFactory
>10:49:27,796 WARN [ServiceController] Problem starting service persistence.units:jar=EJB.jar,unitName=PostgresDS
>javax.naming.NameNotFoundException: PostgresDS 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.interfaces.NamingContext.lookup(NamingContext.java:625)
> at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
> at javax.naming.InitialContext.lookup(InitialContext.java:351)
> at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:240)
> 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 org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:99)
> at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
> at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
> 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 org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
> at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
> at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
> at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
> at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
> at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
> at $Proxy0.start(Unknown Source)
> at org.jboss.system.ServiceController.start(ServiceController.java:417)
> at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
> at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
> at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
> at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
> at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
> at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
> at $Proxy98.start(Unknown Source)
> at org.jboss.ejb3.JmxKernelAbstraction.install(JmxKernelAbstraction.java:82)
> at org.jboss.ejb3.Ejb3Deployment.startPersistenceUnits(Ejb3Deployment.java:626)
> at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:475)
> at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:139)
> at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
> at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
> 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 org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
> at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
> at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
> at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
> at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
> at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
> at $Proxy0.start(Unknown Source)
> at org.jboss.system.ServiceController.start(ServiceController.java:417)
> at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
> at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
> at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
> at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
> at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
> at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
> at $Proxy29.start(Unknown Source)
> at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:449)
> 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 org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
> at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
> at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
> at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
> at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
> at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
> at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
> at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
> at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
> at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
> at $Proxy30.start(Unknown Source)
> at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
> at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
> at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
> at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
> at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
> at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
> at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
> at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
> at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
> at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
> at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
一般j2ee server都提供这个功能
j2ee server是什么意思,提供了什么功能。
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>你的数据源配置文件中:<connection-url>jdbc:postgresql://127.0.0.1/TESTEJB </connection-url> ; postgresql是什么,我倒是没见过
如果数据库是MySQL的话应该是:<connection-url>jdbc:mysql://localhost:3306/自己建的数据库?useUnicode=true&characterEncoding=gb2312</connection-url>
顺便说下 不需要配置JNDI,一般部署后(JBoss),服务器会把资源挂到JNDi树上的,可以在控制台中查看,是否都挂上去了