gpt4 book ai didi

jdbc - 在 Jetty 中配置 JNDI 资源 SQL

转载 作者:行者123 更新时间:2023-12-04 21:14:18 26 4
gpt4 key购买 nike

我在 Jetty 中配置 JNDI 资源有很多困难。我已经使用 context.xml 和 Resource 节点轻松地在 Tomcat 中工作。已经尝试在 jetty-env.xml 和它们的 context.xml 文件版本中指定 Jetty 中的资源,但我最终得到了相同的异常。这是资源定义的 context.xml 版本:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/SQLDB</Arg>
<Arg>
<New class="com.microsoft.sqlserver.jdbc.SQLServerDriver">
<Set name="serverName">SQLDB.domain.com</Set>
<Set name="portNumber">1433</Set>
<Set name="databaseName">DBName</Set>
<Set name="userName">UName</Set>
<Set name="password">PWord</Set>
</New>
</Arg>
</New>
</Configure>

当我尝试启动 JNDI 时给出的异常是:
java.lang.NoSuchMethodException: class com.microsoft.sqlserver.jdbc.SQLServerDriver.setServerName(class java.lang.String)
2013-02-01 16:57:39.061:WARN:oejd.DeploymentManager:Unable to reach node goal: started
java.lang.NoSuchMethodException: class com.microsoft.sqlserver.jdbc.SQLServerDriver.setServerName(class java.lang.String)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.set(XmlConfiguration.java:585)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:390)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:819)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1132)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1035)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:783)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:398)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:349)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:302)
at org.eclipse.jetty.deploy.providers.ContextProvider.createContextHandler(ContextProvider.java:86)
at org.eclipse.jetty.deploy.App.getContextHandler(App.java:100)
at org.eclipse.jetty.deploy.bindings.StandardDeployer.processBinding(StandardDeployer.java:36)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:494)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:141)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:145)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:56)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:540)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:403)
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:337)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:121)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:555)
at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:230)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:81)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:96)
at org.eclipse.jetty.server.Server.doStart(Server.java:277)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1265)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:468)
at org.eclipse.jetty.start.Main.start(Main.java:616)
at org.eclipse.jetty.start.Main.main(Main.java:92)

这个异常似乎违反直觉,因为我可以在 Microsoft JDBC Driver 4.0 for SQL Server documentation 中看到serverName 被列为有效属性。

另外,我运行了以下命令来验证是否包含所有预期的 jar 文件。特别是 jndi 和 sqljdbc 的那些。
java -jar start.jar --list-options

以下是我用来获取当前位置的教程和文档的链接。
http://wiki.eclipse.org/Jetty/Feature/JNDI

http://www.eclipse.org/jetty/documentation/current/jndi-datasource-examples.html

http://www.eclipse.org/jetty/documentation/current/jndi.html#configuring-env-entries

社区的任何见解将不胜感激!

最佳答案

您必须遵循 Jetty7 的这些说明。 .
老年人 Jetty .

我看到您正在尝试使用 Sql Server,因此,您需要使用 net.sourceforge.jtds.jdbcx.JtdsDataSource 如示例所示:

<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/DSTest</Arg>
<Arg>
<New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
<Set name="User">user</Set>
<Set name="Password">pass</Set>
<Set name="DatabaseName">dbname</Set>
<Set name="ServerName">localhost</Set>
<Set name="PortNumber">1433</Set>
</New>
</Arg>
</New>

另外,添加到 [jetty_home]/lib/ext 所需的库 jTDS或使用 Maven: Maven dependency :

关于jdbc - 在 Jetty 中配置 JNDI 资源 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14656442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com