[英]How to set up jndi.properties for DataStore?
I'm struggling to set connect a Java program to MySQL using JPA/Hibernate. 我正在努力设置使用JPA / Hibernate将Java程序连接到MySQL。
I'm currently getting the following error when I try to call createEntityManagerFactory()
: 当我尝试调用
createEntityManagerFactory()
时,当前出现以下错误:
[main] ERROR org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: java:jdbc/myDataDS
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:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
Googling seems to indicate that I need a jndi.properties file in META-INF in my classpath, but I can't seem to find any information about what that file should contain in my case. 谷歌搜索似乎表明我在我的类路径中的META-INF中需要一个jndi.properties文件,但是我似乎找不到有关该文件应包含的内容的任何信息。
Edit: I'm running this stand-alone, for the time being. 编辑:我暂时正在运行此独立。
A jndi.properties
file should be at the root of the classpath and typically contains the URL of the JNDI server and the initial context factory to use. jndi.properties
文件应位于类路径的根目录,并且通常包含JNDI服务器的URL和要使用的初始上下文工厂。 For example, with JBoss: 例如,对于JBoss:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
But, when using Hibernate, you should actually declare these properties in the hibernate.cfg.xml
. 但是,使用Hibernate时,实际上应该在
hibernate.cfg.xml
声明这些属性。 For example, with WebLogic: 例如,使用WebLogic:
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="jndi.url">t3://127.0.0.1:7001</property>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.