Spring + Felix war = FileNotFoundException

标签 spring osgi glassfish-3 apache-felix

是否可以在 felix 的 war bundle 中使用 spring?我在 glassfish 3.1 上使用 spring 3.0.5 和 felix

我尝试输入component-scan在 felix 中的 OSGI war 包内标记,我得到以下异常。

我看到一个similar bug已经解决了Equinox,那么felix呢?是否有解决此问题的解决方法或解决方案?

P.S:如果我在 web.xml contextConfigLocation 中使用 * 定义路径,则会引发相同的异常, 例如:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/spring/*.xml</param-value>
</context-param>

异常(exception):
2012-02-08 18:30:23,194 [pool-28-thread-1] (PathMatchingResourcePatternResolver.java:532) WARN - Cannot search for matching files underneath URL [bundle://275.0:2/examples/services/] because it does not correspond to a directory in the file system 
java.io.FileNotFoundException: URL [bundle://275.0:2/examples/services/] cannot be resolved to absolute file path because it does not reside in the file system: bundle://275.0:2/examples/services/ 
at org.springframework.util.ResourceUtils.getFile(Res ourceUtils.java:204) 
at org.springframework.core.io.AbstractFileResolvingR esource.getFile(AbstractFileResolvingResource.java :52) 
at org.springframework.core.io.UrlResource.getFile(Ur lResource.java:168) 
at org.springframework.core.io.support.PathMatchingRe sourcePatternResolver.doFindPathMatchingFileResour ces(PathMatchingResourcePatternResolver.java:528) 
... 
2012-02-08 18:30:23,194 [pool-28-thread-1] (PathMatchingResourcePatternResolver.java:353) DEBUG - Resolved location pattern [classpath*:examples/services/**/*.class] to resources [] 

应用程序上下文.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx">

    <context:annotation-config/>

    <tx:annotation-driven />

    <context:component-scan base-package="examples.services" />

</beans>

谢谢你的任何提示

最佳答案

我发现有两种解决方法可以解决它。我仍然很高兴听到 felix 的真正解决方案。

解决方法是:

  • 使用春分代替 felix :)
  • (一个丑陋的)创建一个临时文件夹并将所有类提取到其中。用函数
  • 创建一个类 org.eclipse.core.runtime.FileLocator

    public static URL resolve(URL url) throws IOException



    并从该文件夹返回内容的 url,例如:
        String path = url.getPath(); 
        String str;
        if(path.contains("com")){
            str = path.substring(path.indexOf("com"));
        }
        return new URL("file:\\c:\\temp_classes\\"+str);
    

    关于Spring + Felix war = FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9215544/

    相关文章:

    spring - 如何从 PageRequest 禁用计数查询以获取总页数?

    java - spring工具套件休息服务不引用函数

    Spring 启动测试 - 找不到测试属性

    java - 是否有 OSGi 版本的 Guava 源代码(用于 Eclipse)?

    osgi - Felix maven-bundle-plugin 传递依赖问题

    java - 使用不同的根对象类型调用相同的 Spring EL 表达式失败

    glassfish - 如何升级 Glassfish ?

    macos - quartz JobStore : JobPersistenceException: Couldn't retrieve trigger: ClassNotFoundException

    mongodb - java.lang.NoClassDefFoundError : com/mongodb/ServerAddress

    Java 线程上下文类加载器 - 它是如何工作的?