3

我很难让 Spring 项目在 Virgo 3.0.2 上运行,更准确地说是读取 applicationContext 文件,这是我的 StackTrace:

[2012-05-01 09:44:37.681] DEBUG Thread-130                      o.e.gemini.web.tomcat.internal.loading.BundleWebappClassLoader      Searching the application's bundle 
[2012-05-01 09:44:37.681] TRACE Thread-130                   org.springframework.osgi.util.DebugUtils                          Could not find class [org.springframework.web.context.ContextLoaderListener] required by [null(BizTouch.Web)] scanning available bundles 
[2012-05-01 09:44:37.682] DEBUG Thread-130                   o.e.gemini.web.tomcat.internal.loading.BundleWebappClassLoader    loadClass(org.eclipse.gemini.web.tomcat.internal.loading.BundleWebappClassLoader, false) 
[2012-05-01 09:44:37.682] DEBUG Thread-130                   o.e.gemini.web.tomcat.internal.loading.BundleWebappClassLoader      Searching the application's bundle 
[2012-05-01 09:44:37.683] TRACE Thread-130                   org.springframework.osgi.util.DebugUtils                          Could not find class [org.eclipse.gemini.web.tomcat.internal.loading.BundleWebappClassLoader] required by [null(BizTouch.Web)] scanning available bundles 
[2012-05-01 09:44:37.683] ERROR Thread-130                   o.a.c.core.ContainerBase.[Catalina].[localhost].[/BizTouch.Web]   Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    at org.eclipse.gemini.web.tomcat.internal.loading.BundleWebappClassLoader.loadClass(BundleWebappClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at      org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    at java.lang.Thread.run(Thread.java:619)

我的清单文件:

Manifest-Version: 2.0
Tool: Bnd-0.0.386
Meta-Persistence: META-INF/persistence.xml
Bundle-Name: com.apptivit.biztouch.web
DynamicImport-Package: *
Bundle-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.apptivit.biztouch.web
Import-Library: org.springframework.spring;version="[3.0.5.RELEASE,3.0.5.RELEASE]"
Import-Bundle: com.springsource.com.mysql.jdbc;version="[5.1.6,5.1.6]"
Import-Package: com.apptivit.biztouch.business.timeline;com.apptivit.biztouch.dao;javax.el;javax.servlet;javax.servlet.http;javax.servlet.jsp;javax.servlet.jsp.el;javax.servlet.jsp.tagext;com.apptivit.biztouch.models;org.eclipse.virgo.web.dm
Bundle-Vendor: Apptiv-IT
Web-ContextPath: BizTouch.Web
Spring-Context: WEB-INF/spring/appServlet/appServlet-context.xml

我的 web.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/appServlet-context.xml</param-value>
        </init-param>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

如果需要,我已准备好提供完整的项目,我尝试了各种配置,但总是遇到同样的问题。非常感谢。

4

1 回答 1

1

问题是:

ClassNotFoundException:org.springframework.web.context.ContextLoaderListener

您的应用程序没有导入这个包,并且类加载器找不到这个类,要解决这个问题,您需要在清单中添加 import 语句:

导入包:org.springframework.web.context;version="[3.0.5.RELEASE,3.0.5.RELEASE]"

并且可能是您在 web.xml 中使用的其他内容,例如:

org.eclipse.virgo.web.dm
org.springframework.web.servlet
org.springframework.osgi.web.context.support
于 2012-05-09T09:58:05.177 回答