除非我添加了验证回调方法,否则不会调用我的iPOJO组件的注入回调。
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控制台列出该组件是有效的。 问题是什么?
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"
答案 0 :(得分:1)
创建对象时将调用@Bind回调(当需要时,将调用@Bind回调,因此在您第一次使用已发布服务的情况下)。
不是添加@Validate回调,而只是在需要提前创建对象时,只需使用:
@Component(immediate=true)