xml解析为啥会出现这种错误?有时候有,有时候没有,上个创建的项目不会,这个就会了
https://blog.csdn.net/wq1256314069/article/details/127040765
你的这些mapper的xml以及pojo等,是通过自动创建的吗? 建议通过自动创建的方式来生成这些文件。在csdn上搜一下用Mybatis generator生成代码,掌握这个技术,开发速度会大大提升。
不知道你这个问题是否已经解决, 如果还没有解决的话: try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
Document document = documentBuilderFactory.newDocumentBuilder().
parse(new FileInputStream(dstFile));
NodeList nodeList = document.getElementsByTagNameNS(XMLSignature.XMLNS , "Signature");
if(nodeList.getLength() == 0){
throw new Exception("Cannot find Signature element");
}
DOMValidateContext validateContext = new DOMValidateContext(new X509KeySelector() , nodeList.item(0));
XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance("DOM");
XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(validateContext);
boolean result = xmlSignature.validate(validateContext);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
public class X509KeySelector extends KeySelector {
@Override
public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context)
throws KeySelectorException {
Iterator keyInfos = keyInfo.getContent().iterator();
while (keyInfos.hasNext()) {
XMLStructure xmlStructure = (XMLStructure) keyInfos.next();
if (!(xmlStructure instanceof X509Data)) {
continue;
}
X509Data x509Data = (X509Data) xmlStructure;
Iterator x509s = x509Data.getContent().iterator();
while (x509s.hasNext()) {
Object object = x509s.next();
if (!(object instanceof X509Certificate)) {
continue;
}
final PublicKey publicKey = ((X509Certificate) object).getPublicKey();
if (algEquals(method.getAlgorithm() , publicKey.getAlgorithm())) {
return new KeySelectorResult() {
@Override
public Key getKey() {
return publicKey;
}
};
}
}
}
throw new KeySelectorException("No key found");
}
static boolean algEquals(String algURI , String algName){
if (algName.equalsIgnoreCase("DSA") && algURI.equalsIgnoreCase(SignatureMethod.DSA_SHA1)
|| algName.equalsIgnoreCase("RSA") && algURI.equalsIgnoreCase(SignatureMethod.RSA_SHA1)) {
return true;
}
return false;
}
}