Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
2 replies Latest Post - ‏2013-07-10T09:52:52Z by weixinlu
weixinlu
weixinlu
5 Posts
ACCEPTED ANSWER

Pinned topic OSGi, spring component-scan and WAS Liberty Profile

‏2013-07-09T01:36:57Z |

Hello,

 
I'm using Websphere application server v8.5 Liberty Profile developing a web osgi bundle. Development tool is IBM RAD. In that bundle, I used Spring (context:component-scan) and got exceptions says "java.io.FileNotFoundException: URL [bundleresource://873.fwk-1377360156/com/xxx/xx/] cannot be resolved to absolute file path because it does not reside in the file system".
 
I googled and it seems a common problem. But all solution I found is using Eclipse Gemini blueprint. I'm wondering if there is another solution for this. Or if WAS Liberty Profile can support that. I found some ibm osgi jars in the lib folder, seems they are arise blueprint.
 
Attached some of my code and config files as below:
 
Web.xml
<servlet>
<display-name>spring</display-name>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>  
    <servlet-name>spring</servlet-name>  
    <url-pattern>/*</url-pattern>  
</servlet-mapping>
 
spring-servlet.xml
<!-- Scans the classpath of this application for @Components to deploy as beans -->
<context:component-scan base-package="com.xxx.xx" />
 
When I run application and access it, I got below exceptions in console:
[WARN]18:43:06(PathMatchingResourcePatternResolver.java:530) - Cannot search for matching files underneath URL [bundleresource://873.fwk-1377360156/com/xxx/xx/] because it does not correspond to a directory in the file system
java.io.FileNotFoundException: URL [bundleresource://873.fwk-1377360156/com/xxx/xx/] cannot be resolved to absolute file path because it does not reside in the file system: bundleresource://873.fwk-1377360156/com/xxx/xx/
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:205)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
at org.springframework.core.io.UrlResource.getFile(UrlResource.java:169)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:526)
at org.springframework.web.context.support.ServletContextResourcePatternResolver.doFindPathMatchingFileResources(ServletContextResourcePatternResolver.java:92)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:347)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:266)
at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1250)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:228)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1419)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:527)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:441)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:161)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:322)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadOnStartupCheck(ServletWrapper.java:1369)
at com.ibm.ws.webcontainer.webapp.WebApp.doLoadOnStartupActions(WebApp.java:1091)
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinally(WebApp.java:1059)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:965)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6038)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:421)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.createRunnableHandler(DynamicVirtualHost.java:241)
at com.ibm.ws.http.internal.VirtualHostImpl.discriminate(VirtualHostImpl.java:182)
at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:169)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:448)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:382)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:282)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:253)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:174)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:83)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:502)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:550)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:899)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:981)
at com.ibm.ws.threading.internal.Worker.executeWork(Worker.java:439)
at com.ibm.ws.threading.internal.Worker.run(Worker.java:421)
at java.lang.Thread.run(Thread.java:770)

 

  • Graham_Charters
    Graham_Charters
    14 Posts
    ACCEPTED ANSWER

    Re: OSGi, spring component-scan and WAS Liberty Profile

    ‏2013-07-10T08:44:23Z  in response to weixinlu
    Hi,
     
    As you've observed, the component-scan configuration scans visible classes for Spring annotations.  Outside OSGi, the scope of this is the classpath, and inside, it's what is visible to the bundle.  You probably already found this, but it describes the issue of how traditional Spring application contexts don't fit well with OSGi modularity: http://stackoverflow.com/questions/8331583/spring-component-scan-in-osgi-finds-nothing .
     
    Spring DM was created to address this and standardized as the OSGi Blueprint specification.  We provide an implementation of Blueprint in Full Profile WAS and the Liberty Profile.  The annotations were not standardized, nor were the frameworks that build on the Spring component model (e.g. Spring MVC), so these are not provided in the WAS implementation.  If you need those features, then you're are probably looking at trying to integrate the Gemini Blueprint implementation (this is the Spring DM project contributed to Eclipse).  This isn't something I have first-hand experience of.  If you can use alternatives that WAS does support (e.g. JSR or servlet/jsp), then I would recommending using the Blueprint support provided in the product.
     
    I hope this helps.
    • weixinlu
      weixinlu
      5 Posts
      ACCEPTED ANSWER

      Re: OSGi, spring component-scan and WAS Liberty Profile

      ‏2013-07-10T09:52:52Z  in response to Graham_Charters

      Hi,

      Thanks for reply! I do find it will spend too much time to investigate how to make Gemini Blueprint work in RAD + WAS. Discussed with my colleague, we decided not to use component-scan.