{"id":5292,"date":"2014-03-30T20:23:41","date_gmt":"2014-03-30T20:23:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/spring-component-scan-broken-in-osgi-container-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:23:41","modified_gmt":"2014-03-30T20:23:41","slug":"spring-component-scan-broken-in-osgi-container-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/spring-component-scan-broken-in-osgi-container-collection-of-common-programming-errors\/","title":{"rendered":"Spring component-scan broken in osgi container-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to integrate spring DI into an existing jaxws project. I&#8217;ve got this working locally on tomcat but when I deploy to the remote container it doesn&#8217;t appear to do the classpath scanning. I can see in the logs that on tomcat it registers my @Components as beans but on the remote server they&#8217;re not mentioned at all.<\/p>\n<p>What I do see is the stacktrace below. It looks like it&#8217;s down to the quirky web container I have to use. It&#8217;s the &#8220;integrated application server for IBM i&#8221;. http:\/\/www-03.ibm.com\/systems\/i\/software\/ias\/ I believe this is built on the eclipse architecture and when you install a war file it converts each app into a bundle. That&#8217;s great but it&#8217;s breaking my classpath scanning. \ud83d\ude41<\/p>\n<p>Does anyone have a solution for this? Thanks<\/p>\n<pre><code>673 [Thread-6] WARN  org.springframework.core.io.support.PathMatchingResourcePatternResolver  - Cannot search for matching files underneath URL [bundleresource:\/\/32\/com\/company\/application\/] because it does not correspond to a directory in the file system\njava.io.FileNotFoundException: URL [bundleresource:\/\/32\/com\/company\/application\/] cannot be resolved to absolute file path because it does not reside in the file system: bundleresource:\/\/32\/com\/company\/application\/\n    at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:205)\n    at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)\n    at org.springframework.core.io.UrlResource.getFile(UrlResource.java:169)\n    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:526)\n    at org.springframework.web.context.support.ServletContextResourcePatternResolver.doFindPathMatchingFileResources(ServletContextResourcePatternResolver.java:92)\n    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:347)\n    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:266)\n    at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1269)\n    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:248)\n    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)\n    at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)\n    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)\n    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)\n    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)\n    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)\n    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)\n    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)\n    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)\n    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)\n    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)\n    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)\n    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)\n    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)\n    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)\n    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)\n    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)\n    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)\n    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)\n    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)\n    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)\n    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)\n    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)\n    at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1678)\n    at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:371)\n    at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:347)\n    at com.ibm.ws.webcontainer.webapp.WebGroup.addWebApplication(WebGroup.java:134)\n    at com.ibm.ws.webcontainer.VirtualHost.addWebApplication(VirtualHost.java:145)\n    at com.ibm.ws.webcontainer.WebContainer.addWebApp(WebContainer.java:542)\n    at com.ibm.ws.webcontainer.WebContainer.addWebApplication(WebContainer.java:513)\n    at com.ibm.pvc.internal.webcontainer.trackers.WebApplicationServiceTracker.addingService(WebApplicationServiceTracker.java:94)\n    at org.osgi.util.tracker.ServiceTracker$Tracked.trackAdding(ServiceTracker.java:1064)\n    at org.osgi.util.tracker.ServiceTracker$Tracked.trackInitialServices(ServiceTracker.java:926)\n    at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:330)\n    at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:274)\n    at com.ibm.pvc.internal.webcontainer.trackers.XMLParserServiceTracker.initializeTrackers(XMLParserServiceTracker.java:520)\n    at com.ibm.pvc.internal.webcontainer.trackers.XMLParserServiceTracker.startWebcontainer(XMLParserServiceTracker.java:235)\n    at com.ibm.pvc.internal.webcontainer.trackers.XMLParserServiceTracker.addingService(XMLParserServiceTracker.java:140)\n    at org.osgi.util.tracker.ServiceTracker$Tracked.trackAdding(ServiceTracker.java:1064)\n    at org.osgi.util.tracker.ServiceTracker$Tracked.trackInitialServices(ServiceTracker.java:926)\n    at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:330)\n    at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:274)\n    at com.ibm.pvc.internal.webcontainer.WebContainerActivator.start(WebContainerActivator.java:45)\n    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:1009)\n    at java.security.AccessController.doPrivileged(AccessController.java:251)\n    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1003)\n    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:984)\n    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:350)\n    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:279)\n    at com.ibm.rcp.internal.util.BundleManager.start(BundleManager.java:74)\n    at com.ibm.rcp.internal.util.BundleManager.start(BundleManager.java:179)\n    at com.ibm.rcp.lifecycle.internal.application.BundleControlImpl.start(BundleControlImpl.java:125)\n    at com.ibm.rcp.lifecycle.internal.application.BundleControlImpl.start(BundleControlImpl.java:106)\n    at com.ibm.rcp.lifecycle.application.BundleControl.start(BundleControl.java:89)\n    at com.ibm.lwi.application.LWIApplication.run(LWIApplication.java:149)\n    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)\n    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n    at java.lang.reflect.Method.invoke(Method.java:600)\n    at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)\n    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:195)\n    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)\n    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)\n    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)\n    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)\n    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)\n    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n    at java.lang.reflect.Method.invoke(Method.java:600)\n    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:561)\n    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:501)\n    at org.eclipse.equinox.launcher.Main.run(Main.java:1239)\n    at org.eclipse.equinox.launcher.Main.main(Main.java:1215)\n    at org.eclipse.core.launcher.Main.main(Main.java:30)\n    at com.ibm.lwi.LaunchLWI$1.run(LaunchLWI.java:731)  \n<\/code><\/pre>\n<p>Looking at the code that throws the exception, it&#8217;s checking if the protocol is file:\/\/.<\/p>\n<pre><code>if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {\n            throw new FileNotFoundException(\n                    description + \" cannot be resolved to absolute file path \" +\n                    \"because it does not reside in the file system: \" + resourceUrl);\n<\/code><\/pre>\n<p>I can see that the app has been exploded onto the filesystem. I wonder if there is a way to override this loader in spring to not care about the protocol and obviously still work? I don&#8217;t care for the osgi features of the container. I just want my app to deploy.<\/p>\n<p>The fallback seems to be abandon classpath scanning in favour of defining beans in xml but that;d be a real step back imo. \ud83d\ude41<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to integrate spring DI into an existing jaxws project. I&#8217;ve got this working locally on tomcat but when I deploy to the remote container it doesn&#8217;t appear to do the classpath scanning. I can see in the logs that on tomcat it registers my @Components as beans but on the remote server they&#8217;re [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5292","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5292"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5292\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}