有没有一种方法可以确保具有自动连接到另一个组件的组件的组件的自动装配组件在构造后进行初始化? 例如,如果我有3个组成部分...
@Component
public class ComponentC {
@Autowired
private Component someOtherComponent
}
@Component
public class ComponentB {
@Autowired
private ComponentC componentC
}
@Component
public class ComponentA {
@Autowired
private ComponentB componentB
@PostConstruct
public void init() {
// how can I ensure that componentC and someOtherComponent is initialized and ready?
}
}
如果我在ComponentC和ComponentB的构造函数上添加@Autowired,并将bean作为参数传递,那是否可以实现我想要的目的?
答案 0 :(得分:0)
将function recordNearbyBeacon(major, minor, pathLossVs1m) { ... }
navigator.bluetooth.requestLEScan({
filters: [{manufacturerData: {0x004C: {dataPrefix: new Uint8Array([
0x02, 0x15, // iBeacon identifier.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 // My beacon UUID.
])}}}],
options: {
keepRepeatedDevices: true,
}
}).then(() => {
navigator.bluetooth.addEventListener('advertisementreceived', event => {
let appleData = event.manufacturerData.get(0x004C);
if (appleData.byteLength != 23) {
// Isn’t an iBeacon.
return;
}
let major = appleData.getUint16(18, false);
let minor = appleData.getUint16(20, false);
let txPowerAt1m = -appleData.getInt8(22);
let pathLossVs1m = txPowerAt1m - event.rssi;
recordNearbyBeacon(major, minor, pathLossVs1m);
});
})
带到构造函数级别,并强制spring在类提示之后添加组件。