org.springframework.data.mongodb.core.convert.DefaultDbRefResolver上的NullpointerException.< c linit>(DefaultDbRefResolver.java:57) [英] Nullpointerexception at org.springframework.data.mongodb.core.convert.DefaultDbRefResolver.<c linit>(DefaultDbRefResolver.java:57)
问题描述
由于我一直在寻找这种异常的答案,但在任何地方都找不到,因此,我将在此留下这篇文章,以供将来参考.因此,如果有人遇到此问题,欢迎您.
As I have looked for an answer to this exception, but didn't find it anywhere, I'll leave this post here for future reference. So if anyone else runs into this problem, you are welcome.
我正在使用maven shade plugin
与org.springframework.data:spring-data-mongodb:1.4.0.RELEASE
在创建jar并使用java -jar Foo-0.0.1-SNAPSHOT.jar
推荐答案
和答案:
The error is here: https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolver.java in this line:
private static final boolean IS_SPRING_4_OR_BETTER = SpringVersion.getVersion().startsWith("4");
如果
SpringVersion.getVersion
无法从包中检索版本号,则返回null.由于依赖项是从带阴影的jar中提取的,因此没有用于从中检索版本号的程序包,并且.startsWith("4")
会引发NullPointerException
.
SpringVersion.getVersion
returns null if it cannot retrieve the version number from the package. As the dependencies are extracted in the shaded jar, there is no package to retrieve the version number from and .startsWith("4")
throws a NullPointerException
.
要解决此问题(这是一种快速而肮脏的解决方案,但它可以工作),请在源文件夹中创建一个包org.springframework.core
并创建以下类(我正在使用4.0.2版的springframework-释放):
To solve this issue (well it's kind of a quick and dirty solution, but it works), create a package org.springframework.core
in your source folder and create the following class (I am using the springframework in version 4.0.2-RELEASE):
package org.springframework.core;
/**
* for spring data mongodb
* it can't determine the springversion in the shaded jar
*/
public class SpringVersion {
public static String getVersion() {
return "4.0.2-RELEASE";
}
}
该类将覆盖原始的SpringVersion
类文件.
The class will overwrite the original SpringVersion
class file.
这篇关于org.springframework.data.mongodb.core.convert.DefaultDbRefResolver上的NullpointerException.< c linit>(DefaultDbRefResolver.java:57)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!