iPOJO除非添加了validate back,否则不会调用组件注入回调



我的iPOJO组件的注入回调不会被调用,除非我添加validate回调方法。

import javax.swing.DefaultBoundedRangeModel;
import org.apache.felix.ipojo.annotations.*;
import org.osgi.service.log.*;
@Component
@Instantiate
@Provides
public class MyBoundedRangeModel extends DefaultBoundedRangeModel {
  @Requires
  org.osgi.service.log.LogService logService;
  @Bind
  public void bindLogService(LogService logService) {
    System.out.println("Binded the log service");
  }
  @Unbind
  public void unbindLogService(LogService logService) {
    System.out.println("Unbinded the log service");
  }
//  @Validate
//  public void validate(){
//      System.out.println("Validated the pdf bounded range model");
//  }
}

但是OSGi控制台列出了当我输入命令"instances"时组件是有效的。有什么问题?

g! instances
Instance org.apache.felix.ipojo.arch.gogo.Arch-0 -> valid 
Instance temp.MyBoundedRangeModel-0 -> valid 

g! Instance temp.MyBoundedRangeModel-0
instance name="temp.MyBoundedRangeModel-0" state="valid" bundle="7" component.type="temp.MyBoundedRangeModel"
  handler name="org.apache.felix.ipojo:requires" state="valid"
    requires specification="org.osgi.service.log.LogService" id="org.osgi.service.log.LogService" optional="false" aggregate="false" proxy="true" binding-policy="dynamic" state="resolved"
      selected service.id="22"
      matches service.id="22"
    requires specification="org.osgi.service.log.LogService" id="LogService" optional="false" aggregate="false" proxy="true" binding-policy="dynamic" state="resolved"
      selected service.id="22"
      matches service.id="22"
  handler name="org.apache.felix.ipojo:provides" state="valid"
    provides specifications="[javax.swing.BoundedRangeModel,java.io.Serializable]" state="registered" service.id="51"
      property name="instance.name" value="temp.MyBoundedRangeModel-0"
      property name="factory.name" value="temp.MyBoundedRangeModel"
  handler name="org.apache.felix.ipojo:architecture" state="valid"

@Bind回调将在创建对象时调用(当需要时,因此在您的示例中,当第一次使用已发布的服务时)。

不需要添加@Validate回调,并且只在需要早期创建对象时使用:

@Component(immediate=true) 

相关内容

  • 没有找到相关文章

最新更新