将Spring MVC Dispatcher Servlet注册到Bundle Activator中的OSGI核心服务注册的问题

时间:2015-05-05 23:33:26

标签: spring-mvc osgi-bundle

使用Bundle Activator,尝试将Spring MVC的Dispatcher Servlet注册到服务注册,但是

  

引起:java.io.FileNotFoundException:无法打开   ServletContext资源[/WEB-INF/helloworld-servlet.xml] at   org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:118)     在   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)

Bundle Activator:

public class Activator implements BundleActivator {

private static BundleContext bundleContext;
private ServiceRegistration registration;

public void start(BundleContext context) throws Exception {

    Activator.bundleContext = context;
    try {

        ClassLoader old = Thread.currentThread().getContextClassLoader();

        Hashtable props = new Hashtable();
        props.put("alias", "/spring5");
        props.put("init.message", "Hello World!");
        props.put("contextConfigLocation", "/WEB-INF/helloworld-servlet.xml");
        props.put("contextClass", BAC.class.getName());
        props.put("sling.servlet.extensions", new String[]{"html", "jsp"});
        props.put("sling.servlet.methods", new String[]{"GET", "POST"});
        props.put("sling.servlet.resourceTypes", "examples/sling/spring/mvc/dispatcher/global");


        try {
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
            this.registration = context.registerService(Servlet.class.getName(), new DispatcherServlet(), props);

        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

public void stop(BundleContext context) throws Exception {
    this.registration.unregister();
}

public static BundleContext getBundleContext() {
    return bundleContext;
}

public static void setBundleContext(BundleContext bundleContext) {
    Activator.bundleContext = bundleContext;
}
}

而BAC课程:

import org.osgi.framework.BundleContext;
public class BAC extends org.springframework.web.context.support.XmlWebApplicationContext {

private BundleContext bundleContext;

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

}

public void setBundleContext(BundleContext bundleContext) {
    this.bundleContext = bundleContext;
}
}

MANIFESH.MF INCLUDES:Spring-Context: /WEB-INF/helloworld-servlet.xml

0 个答案:

没有答案