Jetty数据源,Hibernate,找不到数据源

发布于 2024-12-08 19:39:57 字数 1486 浏览 2 评论 0原文

我正在尝试在 Jetty 7.4 中配置数据源。我能够使用 Tomcat context.xml 中的 web 应用程序成功完成此操作。

这是我在 jetty.xml 中的内容(这将是此 jetty 实例中的唯一应用程序,因此我不介意在服务器范围内拥有数据库连接 - 我宁愿不必在战争中配置它) 。它位于最后一个 上方的最底部:

<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>

在我的 web 应用程序的 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 中:

<property name="connection.datasource">java:comp/env/jdbc/myDB</property>

然而,我得到了数据源未找到错误,并且我还看到以下 NameNotFoundException:

javax.naming.NameNotFoundException; remaining name 'env/jdbc/myDB'

当我在启用调试的情况下启动 Jetty 时,看起来它正在注册名称和所有内容,尽管我还远不是 Jetty 专家。我在这里错过了一步吗?还剩下什么?

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.

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>

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>

Finally, in my hibernate.cfg.xml:

<property name="connection.datasource">java:comp/env/jdbc/myDB</property>

Yet, I'm getting a datasource not found error, and I also see the following NameNotFoundException:

javax.naming.NameNotFoundException; remaining name 'env/jdbc/myDB'

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉睡月亮 2024-12-15 19:39:57

是的,这对某些应用程序服务器来说是很奇怪的。有些需要在 JNDI 资源名称前面添加“java:comp/env”,有些则不需要。我认为 Spring 甚至可以在声明 JNDI 资源 bean(如数据源)时启用/禁用该前缀。

尝试:

<property name="connection.datasource">jdbc/myDB</property>

在你的 Hibernate 配置中。

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).

Try:

<property name="connection.datasource">jdbc/myDB</property>

in your Hibernate config.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文