2012-02-09 118 views
3

是否有可能在felix中使用spring内部的war包?我使用弹簧3.0.5与felix上玻璃鱼3.1Spring + Felix war = FileNotFoundException

我试图输入component-scan标记在felix中的OSGI战争捆绑包,我得到下面的异常。

我看到一个similar bug解决了Equinox,那么felix呢?有没有解决这个问题的解决方法?

PS:如果我在web.xml contextConfigLocation限定与*路径相同的抛出异常,例如:

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

例外:

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 [] 

applicationContext.xml中:

​​

谢谢你的任何提示

回答

1

我找到解决方法有两种解决方法。不过我会很高兴听到felix的真正解决方案。

的解决方法是:

  1. 使用春分而不是菲利克斯:)
  2. (难看)创建一个临时文件夹和所有的类提取到它。具有功能

公共静态URL解析(URL链接)创建一个类org.eclipse.core.runtime.FileLocator抛出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); 
0

如果您不介意将自己与Felix捆绑在一起,那么该方案稍微优雅一些​​。

package org.eclipse.core.runtime; 

import java.net.URL; 

import org.apache.felix.framework.BundleRevisionImpl; 
import org.osgi.framework.Bundle; 
import org.osgi.framework.FrameworkUtil; 

public class FileLocator { 
    private FileLocator() {} 

    public static URL resolve(URL url) { 
     if(url == null) { 
      return null; 
     } 
     Bundle bundle = FrameworkUtil.getBundle(FileLocator.class).getBundleContext().getBundle(); 
     BundleRevisionImpl bundleRevision = bundle.adapt(BundleRevisionImpl.class); 
     return bundleRevision.getLocalURL(url.getPort(), url.getPath()); 
    } 
} 

这就要求你导出框架菲利克斯启动使用以下参数:

-Dorg.osgi.framework.system.packages.extra=org.apache.felix.framework