0
votes

I'm developing OSGI application and I need to refresh my application-context.xml during runtime.

I wanted to use

String ctxPath = ....
ApplicationContext ctx = new FileSystemXmlApplicationContext(ctxPath);
((ConfigurableApplicationContext)ctx).refresh();

The problem is - I can't find a way to get path to my application-context.xml (its inside OSGI bundle). The only way I'm aware of, to get inside files of bundle, is to use

InputStream inputStream = new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream("/application-context.xml"));

But I can't get path from InputStream. Any ideas how to make this work?

1
How does your bundle look like at the moment? Are you using spring-dm to start spring in OSGi? - Christian Schneider
What do you mean by "how your bundle look like" exactly? And No, I'm not using spring-dm - Weeedooo
So how do you start spring inside your bundle? Using an Activator? - Christian Schneider
afaik osgi bundle resources cannot be used as files on file system. you may want to use a ClassPathXmlApplicationContext instead of FileSystemXmlApplicationContext; and provide the path "/application-context.xml". - awd

1 Answers

0
votes

The only way I can imagine is to get the InputStream (you could also you the Bundle.getEntry for that) and then save the the file somewhere you would know the path. I have seen this approach in several applications so I assume it is correct.