
Originally Posted by
polosatiy
Does your bundle contains "repo/test.db4o" in jar file?
That's very strange behavior. Here is my example:
Code:
<bean id="settingsBean" class="ru.test.MyBean">
<property name="settings" value="classpath:ru/test/beansettings.xml"/>
</bean>
Code:
class MyBean {
private Resource settings;
}
and it's works.
The bundle does contains the test.db4o file. I looked into the stacktrace and here's what I see.
Code:
"caused by: java.io.FileNotFoundException: OSGi
resource[classpath:taxonomy.db4o|
nd.id=335|bnd.sym=taxonomydaoimplbundle] cannot be resolved to
absolute file path
at org.springframework.osgi.io.OsgiBundleResource.getFile(OsgiBundleResorce.java:345)
at org.springmodules.db4o.ObjectContainerFactoryBean.afterPropertiesSet(bjectContainerFactoryBean.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 45 more
aused by: java.io.FileNotFoundException: OSGi
resource[classpath:taxonomy.db4o|nd.id=335|bnd.sym=taxonomydaoimplbundle]
cannot be resolved to absolute file pah because it does not reside in
the file system: bundle://335.0:1/taxonomy.db4o
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:242
at org.springframework.osgi.io.OsgiBundleResource.getFile(OsgiBundleReso
rce.java:342)
... 48 more"
The exception is being thrown from spring OsgiBundleResource.getFile() method.
It happens when spring module ObjectContainerFactoryBean is trying to
execute the following code :
Code:
if (databaseFile != null) {
container = Db4o.openFile(configuration,
databaseFile.getFile().getAbsolutePath());
log.info("opened db4o local file-based objectContainer @" +
ObjectUtils.getIdentityHexString(container));
}
databaseFile is a org.springframework.core.io.Resource object whose
value is being injected by spring app context, i.e. the db4o path
(classpath:META-INF/spring/repo/test.db4o) . The exception is
happening at OsgiBundleResource.getFile() when
ObjectContainerFactoryBean is trying to execute
databaseFile.getFile().getAbsolutePath()).
Here's the getFile() method in OsgiBundleResource.
Code:
public File getFile() throws IOException {
// locate the file inside the bundle only known prefixes
if (searchType != OsgiResourceUtils.PREFIX_TYPE_UNKNOWN) {
String bundleLocation = bundle.getLocation();
int prefixIndex = bundleLocation.indexOf(ResourceUtils.FILE_URL_PREFIX);
if (prefixIndex > -1) {
bundleLocation = bundleLocation.substring(prefixIndex +
ResourceUtils.FILE_URL_PREFIX.length());
}
File file = new File(bundleLocation, path);
if (file.exists()) {
return file;
}
// fall back to the URL discovery (just in case)
}
try {
return ResourceUtils.getFile(getURI(), getDescription());
}
catch (IOException ioe) {
throw (IOException) new FileNotFoundException(getDescription()
+ " cannot be resolved to absolute file path").initCause(ioe);
Similar to your example, the ObjectContainerFactoryBean is being injected with test.db4o file as a Resource object. I'm guessing, OsgiBundleResource is the one who's doing to discovery and subsequent load of the file. I've no idea why it doesn't work for me.