我在 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 文档中看到 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
社区的任何见解将不胜感激!