制定封闭方法“静态”或删除此set现在,由于变量是静态的,因此它们的值设置的方法应该是静态的,但是我们也在自动化它们,并且静态方法无法自动化。
如果我制作可变的非静态,那么我会得到此错误
发生意外错误:在ORG患者更新时发生错误。无法调用“ com.docasap.patientmanagementservice.helpers.encryptdecrypthelper.buildencryptdecryptdecryptserviceimpl()”,因为“ this.cencryptdecrypthelper”是null
@Slf4j @Component public class StudentEventListener { private static OptStudentRepo optStudentRepo; private static IntStudentRepo intStudentRepo; private static EncryptDecryptHelper encryptDecryptHelper; @Autowired public void setEncryptDecryptHelper(EncryptDecryptHelper encryptDecryptHelp) { encryptDecryptHelper = encryptDecryptHelp; } @Autowired public void setOasPatientRepo(IntStudentRepo intStudentRepo1) { intStudentRepo = intStudentRepo1; } @Autowired public void setOrgPatientRepo(OptStudentRepo optStudentRepo1) { optStudentRepo = optStudentRepo1; } protected EncryptDecryptService determineEncryptionKey(StudentRecord sr) { HashMap<String, Integer> encIds = sr.getEncryptionIds(intStudentRepo, optStudentRepo); EncryptDecryptService encryptDecryptService = encryptDecryptHelper.buildEncryptDecryptServiceImpl(); try { encryptDecryptService.setValue(encIds.get("schoolId").toString(), encIds.get("classId"), SupportedEncryption.AES256); return encryptDecryptService; } catch (InvalidPropertiesFormatException | RuntimeException e) { try { encryptDecryptService.setValue("0", 0, SupportedEncryption.AES256); return encryptDecryptService; } catch (InvalidPropertiesFormatException ex) { throw new RuntimeException(ex); } } } }
在其他几个课程中,我们正在将记录进行加密或解密
@Slf4j
@Component
public class OptStudentEventListener extends StudentEventListener {
@PrePersist
public void encryptRecord(OptStudent os) throws Throwable {
if (os.getIsEncrypted()) {
return;
}
EncryptDecryptService encryptDecryptService = determineEncryptionKey(os);
os.setFirstName(encryptDecryptService.encryptString(pc.getFirstName()));
os.setLastName(encryptDecryptService.encryptString(pc.getLastName()));
os.setMiddleName(encryptDecryptService.encryptString(pc.getMiddleName()));
os.setIsEncrypted(true);
}
}
我如何在没有声纳警告的情况下进行这项工作?
问题是,该类使用
@autowired注入的依赖项,但是spring不支持自动静态字段。解决方案是从变量中静态的静态,并通过构造子注入通过依赖性。这使Spring可以正确管理依赖关系并消除无效问题。此外,确定键合键方法应使用non静态字段访问注入的依赖项。结果,该代码将变为清晰度,更安全,并且将不再触发声纳警告。此外,构造剂注入使依赖项明确,简化测试和代码维护。