IncompatibleClassChangeError: 类未实现所请求的接口 ma.glasnost.orika.Mapper

huangapple 未分类评论48阅读模式
英文:

IncompatibleClassChangeError: Class does not implement the requested interface ma.glasnost.orika.Mapper

问题

我在添加了Orika映射器后,启动我的Web应用程序(使用Spring Boot + Jersey)时遇到了问题:

我有一个Maven依赖项,其中包含一些转换器(我的Web应用程序pom):

  1. <dependency>
  2. <groupId>c.s.r</groupId>
  3. <artifactId>v-c</artifactId>
  4. <version>0.0.11</version>
  5. </dependency>

v-c jar包含一个spring-devtools.properties属性文件,位于src/main/resources/META-INF目录下:

  1. restart.include.orika=/orika-core.*\.jar

并且Orika依赖项在v-c的pom中声明:

  1. <dependency>
  2. <groupId>ma.glasnost.orika</groupId>
  3. <artifactId>orika-core</artifactId>
  4. <version>1.5.4</version>
  5. </dependency>

在v-c项目中,我有一组转换器(位于c.s.r.commun.converter包中),所有转换器都继承自ma.glasnost.orika.CustomMapper<A, B>,并覆盖了public void mapAtoB(final A a, final B b, final MappingContext context)方法。

最后,在我的Web应用程序中,我声明了一个配置类:

  1. import c.s.r.commun.converter.AentityBdtoConverter;
  2. @Configuration
  3. public class OrikaConfiguration {
  4. @Bean
  5. public MapperFacade mapperOrika() {
  6. final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
  7. // 以与下面相同的方式添加来自v-c的所有转换器
  8. mapperFactory.classMap(A.class, B.class)
  9. .customize(new AentityBdtoConverter()).register();
  10. return mapperFactory.getMapperFacade();
  11. }
  12. }

错误原因如下:

  1. Error creating bean with name 'mapperOrika' defined in class path resource [c/s/r/config/OrikaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [ma.glasnost.orika.MapperFacade]: Factory method 'mapperOrika' threw exception; nested exception is java.lang.IncompatibleClassChangeError: Class c.s.r.commun.converter.AentityBdtoConverter does not implement the requested interface ma.glasnost.orika.Mapper
英文:

I'm having an issue starting my web app (spring boot + jersey) after adding orika mapper :

I have a maven dependency that contains some converters (my web app pom):

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;c.s.r&lt;/groupId&gt;
  3. &lt;artifactId&gt;v-c&lt;/artifactId&gt;
  4. &lt;version&gt;0.0.11&lt;/version&gt;
  5. &lt;/dependency&gt;

The v-c jar contains a spring-devtools.properties properties file in the src/main/resources/META-INF directory

  1. restart.include.orika=/orika-core.*\.jar

And Orika dependency is declared in the v-c pom :

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;ma.glasnost.orika&lt;/groupId&gt;
  3. &lt;artifactId&gt;orika-core&lt;/artifactId&gt;
  4. &lt;version&gt;1.5.4&lt;/version&gt;
  5. &lt;/dependency&gt;

And in the v-c project I have a set of converters (within the c.s.r.commun.converter package) that all extend ma.glasnost.orika.CustomMapper&lt;A, B&gt; and override public void mapAtoB(final A a, final B b, final MappingContext context)

Finally, in my web app I'm declaring a configuration class :

  1. import c.s.r.commun.converter.AentityBdtoConverter;
  2. @Configuration
  3. public class OrikaConfiguration {
  4. @Bean
  5. public MapperFacade mapperOrika() {
  6. final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
  7. // adding all of my converters from v-c the same way as below
  8. mapperFactory.classMap(A.class, B.class)
  9. .customize(new AentityBdtoConverter()).register();
  10. return mapperFactory.getMapperFacade();
  11. }
  12. }

The cause error is :

  1. Error creating bean with name &#39;mapperOrika&#39; defined in class path resource [c/s/r/config/OrikaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [ma.glasnost.orika.MapperFacade]: Factory method &#39;mapperOrika&#39; threw exception; nested exception is java.lang.IncompatibleClassChangeError: Class c.s.r.commun.converter.AentityBdtoConverter does not implement the requested interface ma.glasnost.orika.Mapper

huangapple
  • 本文由 发表于 2020年5月19日 18:11:03
  • 转载请务必保留本文链接:https://java.coder-hub.com/61888472.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定