Wiring a prototype in blueprint

后端 未结 2 615
刺人心
刺人心 2021-01-24 10:39

Like Spring, blueprint supports the prototype scope. But unlike Spring I can\'t see any documentation about how to use it.

In Spring you can ask the context to give you

2条回答
  •  甜味超标
    2021-01-24 11:18

    BlueprintContainer.getComponentInstance() does exactly what you are looking for.

    osgi documentation:

    A Blueprint Container represents the managed state of a Blueprint bundle. A Blueprint Container provides access to all managed components. These are the beans, services, and service references. A Blueprint Container can be obtained by injecting the predefined "blueprintContainer" component id.

    Example

    blueprint.xml:

    
    
       
    
    
    
    

    MyService.java:

    // ...
    // create new instance
    MyPrototype myPrototype = 
         (MyPrototype) container.getComponentInstance("myPrototype");
    

    pom.xml:

    
    
      org.apache.aries.blueprint
      org.apache.aries.blueprint.core
      1.3.0
    
    

提交回复
热议问题