Jetty数据源,Hibernate,未找到数据源 [英] Jetty Data Source, Hibernate, datasource not found
问题描述
我试图在Jetty 7.4中配置一个数据源。我能够在Tomcat context.xml中成功地使用我的webapp。
I'm attempting to configure a data source in Jetty 7.4. I was able to do this successfully with my webapp in a Tomcat context.xml.
以下是我在jetty.xml中的内容(这将是唯一的应用程序在这个码头实例中,所以我不介意在服务器范围内拥有数据库连接 - 我宁愿不必在战争中配置它)。它位于最后< / Configure>
的最下方:
Here's what I have in the jetty.xml (this is going to be the only application in this jetty instance, so I don't mind having the DB connection server-wide - I'd rather not have to configure it inside the war). It's at the very bottom just above the last </Configure>
:
<New class="org.eclipse.jetty.plus.jndi.Resource" id="myDB">
<Arg>
<Ref id="Server"/>
</Arg>
<Arg>jdbc/myDB</Arg>
<Arg>
<New class="com.microsoft.sqlserver.jdbc.SQLServerDataSource">
<Set name="URL">jdbc:sqlserver://SERVERNAME;databaseName=DATABASENAME;sendStringParametersAsUnicode=false</Set>
<Set name="user">USERNAME</Set>
<Set name="password">PASSWORD</Set>
</New>
</Arg>
</New>
在我的webapp的WEB-INF / web.xml中:
In my webapp's WEB-INF/web.xml:
<resource-ref>
<description>Database Connection</description>
<res-ref-name>jdbc/myDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
最后,在我的hibernate.cfg.xml中:
Finally, in my hibernate.cfg.xml:
<property name="connection.datasource">java:comp/env/jdbc/myDB</property>
然而,我收到一个datasource未找到的错误,并且我还看到以下NameNotFoundException: / p>
Yet, I'm getting a datasource not found error, and I also see the following NameNotFoundException:
javax.naming.NameNotFoundException; remaining name 'env/jdbc/myDB'
当我启动Jetty并启用调试时,它看起来像它注册了名字和一切,尽管我远不是Jetty的专家。我在这里错过了一步吗?剩下什么?
When I start up Jetty with debugging enabled, it looks like it's registering the name and everything, although I'm far from being a Jetty expert. Did I miss a step here? What's left?
推荐答案
是的,这是一些应用程序服务器的良好合作伙伴。有些需要预先附加到JNDI资源名称的java:comp / env,有些则不需要。我认为当你声明一个JNDI资源bean(比如数据源)时,Spring甚至可以选择启用/禁用这个前缀。
Yep, that's a bizzarerry of some application servers. Some need the "java:comp/env" prependded to the JNDI resource name, some do not. I think Spring has even an option for enabling/disabling that prefix when you declare a JNDI resource bean (like a datasource).
试试:
<property name="connection.datasource">jdbc/myDB</property>
在您的Hibernate配置中。
in your Hibernate config.
这篇关于Jetty数据源,Hibernate,未找到数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!