2012-02-09 24 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