Yup, ManagedServiceFactory would seem like a good fit for what you want.

On Wed, Apr 6, 2011 at 3:07 PM, Daniele Dellafiore
<[email protected]>wrote:

> I think I need to use a ManagedServiceFactory
>
> bundleB defines services
> bungleC, the app, uses B
>
> The services need some other classes from bundleA, for low level storage
> operations, so a connection to a db: host, port, database... all things that
> only the app, C, knows. In a war I'd just inject bean into beans, but here
> is different.
> I cannot instantiate beans from B while B starts in the container, I need
> to ask for a instance of a bean defined in B during the C startup, cause
> only C knows how to configure the bean from A that is needed in the bean in
> B.
>
> Does this make sense?
>
> On Wed, Mar 30, 2011 at 6:57 PM, Allen Lau <[email protected]> wrote:
>
>> I think what you want to do is achievable if you have some custom code to
>> search through all the bundles imported and get the springA.xml and add it
>> to your application context.
>>
>> I see that you are using Spring-DM, so in that case, if you are relying on
>> the extender, why not expose your bundle A beans as services and then
>> reference them from bundle B,C,D, etc.
>>
>>
>> On Wed, Mar 30, 2011 at 5:37 AM, Daniele Dellafiore
>> <[email protected]>wrote:
>>
>> > On Wed, Mar 30, 2011 at 2:23 PM, Daniele Dellafiore
>> > <[email protected]>wrote:
>> >
>> > > Hi have bundle A with a springA.xml file that depends on beans from
>> > bundle
>> > > B springB.xml
>> > > I've added a springA-osgi.xml with declared services and on bundle A
>> > > activation everything works and I have
>> > >
>> > >
>> > > | INFO  | tenderThread-114 | OsgiServiceFactoryBean           |
>> > > r.support.OsgiServiceFactoryBean  301 | 42 -
>> > org.springframework.osgi.core -
>> > > 1.2.0 | Publishing service under classes
>> > > [{in.laz.storage.mongo.StorageTemplate}]
>> > > INFO  | tenderThread-114 | OsgiServiceFactoryBean           |
>> > > r.support.OsgiServiceFactoryBean  301 | 42 -
>> > org.springframework.osgi.core -
>> > > 1.2.0 | Publishing service under classes [{com.mongodb.Mongo}]
>> > >
>> > > both of them (even if I really need to export the first as service,
>> being
>> > > the second injected in the first, anyway.
>> > >
>> > > Then bundleB have a StorageTemplate (first service) autowired into a
>> > bean.
>> > > That does not work:
>> > > "No matching bean of type [in.laz.storage.mongo.StorageTemplate] found
>> > for
>> > > dependency"
>> > >
>> > > even if in springB,xml I import both springA and springA-osgi xml
>> (which
>> > I
>> > > thiink should not be necessary).
>> > >
>> > > Two question here:
>> > > 1. What am I possibly missing that's not making it work?
>> > > 2. I'd like that every bundle that imports springA.xml create some new
>> > > instances of the beans defined there, but I do not think that's what
>> is
>> > > happening: I thing that bundle A instance the beans and export them as
>> > > services, and the same instance is eventually injected into the beans
>> of
>> > > bundle B. That's not what I want, I just want the spring beans
>> definition
>> > to
>> > > stay in bundle A so I do not have to duplicate it in every other
>> bundle,
>> > how
>> > > can I achieve that?
>> > >
>> >
>> > sorry I sent it before was completed.
>> > So basically I am failing doing a thing that's not what i really need to
>> > do,
>> > I just realised :)
>> >
>> > But I am not finding a way to just make a bundle read xml files from
>> other
>> > bundles, that should be supported, isn't it? I expect it to be even
>> easier
>> > than autowiring spring beans exported as osgi services, but if xml are
>> not
>> > exported... that won't work at all.
>> >
>> > Thanks for any hint.
>> >
>>
>
>

Reply via email to