gpt4 book ai didi

java - bean 验证 - hibernate 错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:51:16 25 4
gpt4 key购买 nike

尝试运行命令行应用程序时出现以下异常:

java.lang.ExceptionInInitializerError
at org.hibernate.validator.engine.ConfigurationImpl.<clinit>(ConfigurationImpl.java:52)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:43)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -2
at java.lang.String.substring(String.java:1937)
at org.hibernate.validator.util.Version.<clinit>(Version.java:39)
... 34 more

我做错了什么吗?请建议。

最佳答案

这很奇怪。我将 o.h.v.u.Versionstatic 初始化 block 的相关部分粘贴到具有 main 的类中,并添加了一些可怜的日志记录:

public class VersionTest {
public static void main(String[] args) {
Class clazz = org.hibernate.validator.util.Version.class;

String classFileName = clazz.getSimpleName() + ".class";
System.out.println(String.format("%-16s: %s", "classFileName", classFileName));

String classFilePath = clazz.getCanonicalName().replace('.', '/') + ".class";
System.out.println(String.format("%-16s: %s", "classFilePath", classFilePath));

String pathToThisClass = clazz.getResource(classFileName).toString();
System.out.println(String.format("%-16s: %s", "pathToThisClass", pathToThisClass));

// This is line 39 of `org.hibernate.validator.util.Version`
String pathToManifest = pathToThisClass.substring(0, pathToThisClass.indexOf(classFilePath) - 1)
+ "/META-INF/MANIFEST.MF";
System.out.println(String.format("%-16s: %s", "pathToManifest", pathToManifest));
}
}

这是我运行时得到的输出:

classFileName   : Version.class
classFilePath : org/hibernate/validator/util/Version.class
pathToThisClass : jar:file:/home/pascal/.m2/repository/org/hibernate/hibernate-validator/4.0.2.GA/hibernate-validator-4.0.2.GA.jar!/org/hibernate/validator/util/Version.class
pathToManifest : jar:file:/home/pascal/.m2/repository/org/hibernate/hibernate-validator/4.0.2.GA/hibernate-validator-4.0.2.GA.jar!/META-INF/MANIFEST.MF

在您的情况下,StringIndexOutOfBoundsException:字符串索引超出范围:-2建议:

pathToThisClass.indexOf( classFilePath )

正在返回-1,使得pathToThisClass.substring(0, -2)调用确实是错误的。

这意味着 org/hibernate/validator/util/Version.class 不知何故不是您获得的 pathToThisClass 的一部分。我没有完整的解释,但这一定与您使用 One-Jar 这一事实有关。

您能否运行上述测试类并使用输出更新您的问题?

关于java - bean 验证 - hibernate 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3281585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com