最近在写继承,发现在外面new一下父类,父类里面的注解就不好用了
1.可以通过构造方法注入或者setter注入
例如:
//接口传值
List list = new LinkedList();
CameraClient cameraClient = new CameraClient(); //父类中要引入的类
LightSourceEntity lightSourceEntity = new LightSourceEntity();
signProcess[0] = new SignProcess01();
signProcess[0].setEquipmentNumber(1);
signProcess[0].setLightLoc(6);
signProcess[0].setArea(1);
signProcess[0].setCameraClient(cameraClient); //注入进去
// 父类
private CameraClient cameraClient; // 第一步
// 第二步get,set方法
public CameraClient getCameraClient() {
return cameraClient;
}
public void setCameraClient(CameraClient cameraClient) {
this.cameraClient = cameraClient;
}
// 第三步调用里面的方法
cameraClient.modelClient();
2.如果注解注入mapper失效,可以用一下方法:
@Component
@Slf4j
public class CameraClient {
@Resource
private PlateWatchServerMapper plateWatchServerMapper; //要注入的mapper
public static CameraClient cameraClient; //第一步
// 第二步
@PostConstruct
public void init(){
cameraClient = this;
cameraClient.plateWatchServerMapper = this.plateWatchServerMapper;
}
// 第三步调用里面的方法
cameraClient.plateWatchServerMapper.selectPlateWatchPoint();