首页 \ 问答 \ 杰克逊数据绑定类路径问题(Jackson Databind classpath issue)

杰克逊数据绑定类路径问题(Jackson Databind classpath issue)

我有一个弹簧启动应用程序,当我在我的本地使用“mvn clean install”进行部署时工作正常,但是当通过Jenkin生成战争时,它会抛出以下错误。

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapper' defined in class path resource [com/test/common/TestRestConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'objectMapper' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.SerializationConfig
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
        ... 62 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'objectMapper' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.SerializationConfig
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 74 common frames omitted
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.SerializationConfig
        at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:535)
        at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:452)

我只是尝试比较使用无法比较的2个战争文件,除了用于编译的JDK次要版本之外,我没有看到任何差异。

我试图在我的本地版本和jenkin版本中搜索SerializationConfig.class,

下面的命令的输出是,

find . -type f -name '*.jar' -print0 |  xargs -0 -I '{}' sh -c 'jar tf {} | grep SerializationConfig.class &&  echo {}'

局部战争O / P: -

com/fasterxml/jackson/databind/SerializationConfig.class
./jackson-databind-2.7.3.jar
org/codehaus/jackson/map/SerializationConfig.class
./jackson-mapper-asl-1.9.13.jar
com/fasterxml/jackson/databind/SerializationConfig.class
./jersey-all-2.18.jar

詹金战争O / P: -

com/fasterxml/jackson/databind/SerializationConfig.class
./jersey-all-2.18.jar
org/codehaus/jackson/map/SerializationConfig.class
./jackson-mapper-asl-1.9.13.jar
com/fasterxml/jackson/databind/SerializationConfig.class
./jackson-databind-2.7.3.jar

基本上,我在我的TestRestConfiguration类中注入了ObjectMapper,如下所示,

@Inject
    private ObjectMapper objectMapper;

不确定,为什么通过Jenkin生成的战争文件造成问题。

任何帮助,将不胜感激。


I have a spring boot app which works fine when i do the deploy using "mvn clean install" in my local, but when the war is generated through Jenkin, it is throwing the following error.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapper' defined in class path resource [com/test/common/TestRestConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'objectMapper' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.SerializationConfig
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
        ... 62 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'objectMapper' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.SerializationConfig
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 74 common frames omitted
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.SerializationConfig
        at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:535)
        at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:452)

I just tried comparing the 2 war files using beyond compare and i dont see any diff except the JDK minor version being used to compile.

I tried to search for the SerializationConfig.class in my local build and in the jenkin build,

The output for the below command is,

find . -type f -name '*.jar' -print0 |  xargs -0 -I '{}' sh -c 'jar tf {} | grep SerializationConfig.class &&  echo {}'

Local war O/P :-

com/fasterxml/jackson/databind/SerializationConfig.class
./jackson-databind-2.7.3.jar
org/codehaus/jackson/map/SerializationConfig.class
./jackson-mapper-asl-1.9.13.jar
com/fasterxml/jackson/databind/SerializationConfig.class
./jersey-all-2.18.jar

Jenkin war O/P :-

com/fasterxml/jackson/databind/SerializationConfig.class
./jersey-all-2.18.jar
org/codehaus/jackson/map/SerializationConfig.class
./jackson-mapper-asl-1.9.13.jar
com/fasterxml/jackson/databind/SerializationConfig.class
./jackson-databind-2.7.3.jar

Basically, I inject the ObjectMapper in my TestRestConfiguration class as follows,

@Inject
    private ObjectMapper objectMapper;

Not sure, why the war file being generated through Jenkin is causing problem.

Any help on this will be appreciated.


原文:https://stackoverflow.com/questions/39419160
更新时间:2022-06-26 22:06

最满意答案

通常,您希望使用初始化列表来初始化构造函数中的成员:

canvas()
: fileName("zzz.txt")
{
}

当你这样做:

fileName = "zzz.txt";

您正在尝试为数组分配值,这是不合法的。 您可以使用值初始化数组,但之后不能为其分配值(作为整体)。 initializer-list语法允许您使用适当的值初始化它。

但是,如果您使用的是较旧的编译器,则可能必须使用strcpy

strcpy(fileName,"zzz.txt");

对于可以分配的其他类型,使用initializer-list语法并不是绝对必要的,但它通常仍然是一个好主意。

此外,正如其他人所指出的那样,除非你有充分的理由不这样做,否则你最好使用std::string而不是原始的字符数组。 std::string将允许任意长度的字符串,可以像常规值一样对待。


In general, you want to use an initializer-list to initialize members in a constructor:

canvas()
: fileName("zzz.txt")
{
}

When you do this:

fileName = "zzz.txt";

You are trying to assign a value to an array, which isn't legal. You can initialize an array with values, but you can't assign it a value (as a whole) afterwards. The initializer-list syntax allows you to initialize it with the proper value.

However, if you are using an older compiler, you may have to use strcpy instead:

strcpy(fileName,"zzz.txt");

For other types that can be assigned, using the initializer-list syntax isn't strictly necessary, but it is still usually a good idea.

Also, as others have noted, unless you have a good reason not to, you'd be better off using a std::string instead of a raw array of characters. A std::string will allow for strings of arbitrary length which can be treated like regular values.

相关问答

更多
  • 通常,您希望使用初始化列表来初始化构造函数中的成员: canvas() : fileName("zzz.txt") { } 当你这样做: fileName = "zzz.txt"; 您正在尝试为数组分配值,这是不合法的。 您可以使用值初始化数组,但之后不能为其分配值(作为整体)。 initializer-list语法允许您使用适当的值初始化它。 但是,如果您使用的是较旧的编译器,则可能必须使用strcpy : strcpy(fileName,"zzz.txt"); 对于可以分配的其他类型,使用init ...
  • Hitcount += Br; 您无法为这样的C样式数组添加值。 您需要维护元素计数并添加如下值: Hitcount[count++] = Br; 或者你最好使用std::vector并通过调用push_back添加元素: std::vector Hitcount; // code skipped Hitcount.push_back( Br ); Hitcount += Br; You cannot add value to a C style array like that. ...
  • 将你的cin语句修改为cin >> a >> b; ,这会一次读取多个值,因为cin不存在逗号运算符。 另外,将赋值右侧的结果变量的顺序切换到左侧。 赋值中=的两个操作数是l值,代表左值,应该在左侧,而r值代表右值,应该在右侧。 切换它们,就会出错。 您的新修改代码 double a, b, result; cout << "Please enter your two side lengths (ex:12 5)"; cin >> a >> b; //<-- See '>>' here //sqrt( ...
  • 您获得的错误与解析表达式的方式有关。 你的表达式(简化)如下所示: (a = b) < 10 ? c = 1 : c = 0 三元运算符?:具有比赋值运算符=更高的优先级。 虽然内部=被视为三元的一部分,但最右边的却不是。 所以表达式解析如下: ((a = b) < 10 ? c = 1 : c) = 0; 结果是您尝试将值0分配给不是左值的表达式,即变量名称或取消引用的指针。 你需要括号来解析你想要的方式: ((a = b) < 10) ? (c = 1) : (c = 0); 由于您正在做的是根据 ...
  • 您无法分配给阵列。 你可以做的是使用std::string或使用std::strcpy/std::strncpy ,如 std::strncpy(citizen1.name,"Tim McGuiness", sizeof(taxPayer::name)); 既然你使用C ++,我建议使用std::string , struct taxPayer { std::string name; // the rest }; 那么您可以像在代码中一样分配给它 citizen1.name = "Tim ...
  • 您的成员函数是const限定的。 除非声明为可变,否则不能在const限定的成员函数中修改任何成员变量。 你需要使pDrawMesh可变,从DrawMeshContainer删除const限定,或者找到一些其他方法来完成你想要完成的任何事情。 Your member function is const-qualified. You cannot modify any member variables from within a const-qualified member function unless t ...
  • 你的operator []返回一个int,它不是一个可修改的左值(大概是一个int不能放在赋值的左边)。 您的operator []也被定义得非常奇怪,为什么要编写递增的operator []? 这是你通常写这个的方式 int& operator [](const unsigned int n){return niz[n];} 现在你的代码应该工作,因为你正在返回一个可以递增的引用。 Your operator[] returns an int, which is not a modifiable lva ...
  • 数组不能直接在C中赋值。但是, 包含数组的结构是,所以你可以做的是: word w = { { {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1} } }; memory[0] = w; 使用C99,你可以使用复合文字并说: memory[0] = (struct word){ { {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1} } ...
  • 看来你的意思是以下 while (y != NULL && x == y->right) ^^^ 至于错误消息的含义,那么当你使用赋值运算符时,它的优先级小于等式和逻辑运算符的优先级,事实上 while ( ( y != NULL && x ) = y->right) 考虑到将y的声明放在else语句的代码块中要好得多,因为它仅在此范围内使用 //... else { node* y = x->parent; It seems that you me ...
  • 这是因为您将一个整型常量传递给类似函数的宏FOO(a, b) ,它将预增加运算符应用于其参数。 此宏扩展的结果如下所示: int *p = graph_p + (--2)* 8 + (--3);; 这在C中是非法的,因为操作符需要一个可修改的左值作为其操作数。 这里的另一个问题是,你应该在宏的替代方案中放置一些关键字,并且不要在最后放置分号: #define FOO(a,b) ((--a)* 8 + (--b)) It's because you are passing an integer const ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)