自定义Tomcat领域:ClassNotFoundException

时间:2013-09-11 19:59:32

标签: java tomcat eclipse-virgo

我正在使用Eclipse Virgo(3.6.1)OSGi容器,该容器在Tomcat 7.0.31上运行。我正在尝试根据Tomcat documentation实现自定义身份验证领域,但在尝试启动服务器时遇到了ClassNotFoundException

我的领域实现非常简单;它只是扩展JDBCRealm并覆盖authenticate方法。根据文档,我将这个类编译成一个标题为com.authentication.MyCustomRealm.jar的jar,并将其放在$ SERVER_HOME / lib中。

我添加到tomcat-server.xml的配置如下:

<Realm className="com.authentication.MyCustomRealm"
  resourceName="Custom Realm"
  driverName="{jdbc.driverClassName}"
  dbConnectionName="{jdbc.username}"
  dbConnectionPassword="{jdbc.password}"
  dbConnectionURL="{jdbc.url}"
  userTable="USER_DATA"
  userNameCol="ID" />
</Realm>

这是部分堆栈跟踪:

org.xml.sax.SAXParseException: Error at (103, 40) : com.authentication.MyCustomRealm
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2687)
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2719)
    at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1279)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1303)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2717)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1556)
    at org.eclipse.gemini.web.tomcat.internal.OsgiAwareEmbeddedTomcat.configure(OsgiAwareEmbeddedTomcat.java:309)
    ... 42 common frames omitted com.authentication.MyCustomRealm 
    at org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.doLoadClass(ChainedClassLoader.java:181)
    at org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.loadClass(ChainedClassLoader.java:164)
    at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:144)
    at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1276)

Caused by: java.lang.ClassNotFoundException: com.authentication.MyCustomRealm
    at org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.doLoadClass(ChainedClassLoader.java:181)
    at org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.loadClass(ChainedClassLoader.java:164)
    at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:144)
    at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1276)
    ... 55 common frames omitted

我怀疑我的OSGi配置需要做些什么才能找到类,但我不确定究竟是什么。

1 个答案:

答案 0 :(得分:0)

从堆栈跟踪中,我发现org.eclipse.gemini.web.tomcat包试图加载我的自定义域。我的解决方案是创建一个使用org.eclipse.gemini.web.tomcat作为主机的新片段包。我将自定义域放在这个包中,解决了这个异常。