spring-mvc - OSGi Spring MVC 捆绑噩梦 - java.lang.ClassNotFoundException : org. springframework.context.config.ContextNamespaceHandler 从捆绑中找不到

标签 spring-mvc osgi

我无法让我的 Spring MVC 应用程序作为 OSGi 包运行。这完全难倒了我。

我正在尝试运行 Spring 3 MVC 包,但启动时找不到使用 Spring 所需的命名空间处理程序。我已经为 org.springframework.context 包含了必要的导入包。我检查了 org.springframework.context.config.ContextNamespaceHandler 是否安装在 Virgo 服务器上。在服务器中启动 bundle 时没有错误 - 所以我非常确定必须满足依赖关系。

这是当我尝试向 MVC 调度程序 servlet 发出请求时遇到的异常;-

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]; nested exception is org.springframework.beans.FatalBeanException: NamespaceHandler class [org.springframework.context.config.ContextNamespaceHandler] for namespace [http://www.springframework.org/schema/context] not found; nested exception is java.lang.ClassNotFoundException: org.springframework.context.config.ContextNamespaceHandler not found from bundle [com.osgi-test.spring-mvc-bundle]
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
org.eclipse.gemini.blueprint.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:170)
org.eclipse.gemini.blueprint.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:140)
org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.access$301(AbstractDelegatedExecutionApplicationContext.java:60)
org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$1.run(AbstractDelegatedExecutionApplicationContext.java:168)
org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.normalRefresh(AbstractDelegatedExecutionApplicationContext.java:164)
org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$NoDependenciesWaitRefreshExecutor.refresh(AbstractDelegatedExecutionApplicationContext.java:78)
org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:157)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
javax.servlet.GenericServlet.init(GenericServlet.java:244)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  org.eclipse.virgo.web.tomcat.support.ApplicationNameTrackingValve.invoke(ApplicationNameTrackingValve.java:33)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)

bundle 中的 list 文件如下所示;-

Manifest-Version: 1.0
Export-Package: com.osgi-test.external;version="0.0.1.SNAPSHOT"
Bundle-ClassPath: .,WEB-INF/classes
Built-By: seth
Tool: Bnd-1.50.0
Bundle-Name: spring-mvc-bundle
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.7.0_06
Bundle-Version: 0.0.1.SNAPSHOT
Bnd-LastModified: 1347110247719
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.osgi-test.spring-mvc-bundle
Import-Package: com.osgi-test.external,javax.servlet.http;version="
[2.4,3)",org.eclipse.virgo.web.dm;version="[3.0,4)",org.springfram
ework.context;version="[3.0,4)",org.springframework.stereotype;ver
sion="[3.0,4)",org.springframework.validation;version="[3.0,4)",or
g.springframework.web;version="[3.0,4)",org.springframework.web.bi
nd.annotation;version="[3.0,4) ",org.springframework.web.servlet;v
ersion="[3.0,4)"
Archiver-Version: Plexus Archiver

我读了一篇文章,建议使用

org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext

( http://www.eclipse.org/forums/index.php/m/635463/ )

可能有帮助 - 但对我来说没有什么区别。

我还尝试删除 web.xml 中的 ContextLoaderListener - 但同样没有帮助。

此时我已经失去了想法。任何帮助,非常感谢。

最佳答案

http://thomaskratz.blogspot.in/2012/03/osgi-spring-dispatcherservlet.html

请检查此站点,我认为 spring 在直接注册调度程序 servlet 方面存在问题。但如果您使用上述博客中提到的解决方法,它应该可以工作。

我实际上添加了我在这里尝试的代码片段以供引用:

将以下内容添加到插件的激活器中:

Activator.context = bundleContext;

ServiceReference ref = context.getServiceReference(HttpService.class.getName());
HttpService service = (HttpService) context.getService(ref);

DispatcherServlet servlet = new DispatcherServlet();

Dictionary<String, String> initparam = new Hashtable<String, String>();
initparam.put("contextConfigLocation", "/WebContent/WEB-INF/spring-servlet.xml");
initparam.put("contextClass", "spring3osgi.BAC");

ClassLoader loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());

// this is to register the controller
service.registerServlet("/Spring3OSGi",  servlet, initparam, null);

// provide alias to the WebContent folder
service.registerResources("/Spring3OSGiWebContent", "/WebContent", service.createDefaultHttpContext());

创建BAC类

import org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext;

public class BAC extends OsgiBundleXmlWebApplicationContext {

    public BAC() {
        super();
        setBundleContext(Activator.getContext());

    }

}

关于spring-mvc - OSGi Spring MVC 捆绑噩梦 - java.lang.ClassNotFoundException : org. springframework.context.config.ContextNamespaceHandler 从捆绑中找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12331722/

相关文章:

java - Spring REST 安全 : Enable Basic Authentication only on a specific endpoint

java - JSTL 除法自动舍入为 1 或 0

Spring @RestController 不返回纯文本响应

java - 在 spring mvc 中获取 400 错误

java - 集中配置管理

java - 如何连接 OSGI 包(通过包发送实体)?

java - 在 Eclipse 插件中使用非 OSGi 包

java - 是否可以在@RequestBody 中传递多个对象?

java - 设置 OSGi 包的权限

java - 在抽象类中提供 DI 方法