英文:
IncompatibleClassChangeError: Class does not implement the requested interface ma.glasnost.orika.Mapper
问题
我在添加了Orika映射器后,启动我的Web应用程序(使用Spring Boot + Jersey)时遇到了问题:
我有一个Maven依赖项,其中包含一些转换器(我的Web应用程序pom):
<dependency>
<groupId>c.s.r</groupId>
<artifactId>v-c</artifactId>
<version>0.0.11</version>
</dependency>
v-c jar包含一个spring-devtools.properties
属性文件,位于src/main/resources/META-INF目录下:
restart.include.orika=/orika-core.*\.jar
并且Orika依赖项在v-c的pom中声明:
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.5.4</version>
</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应用程序中,我声明了一个配置类:
import c.s.r.commun.converter.AentityBdtoConverter;
@Configuration
public class OrikaConfiguration {
@Bean
public MapperFacade mapperOrika() {
final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
// 以与下面相同的方式添加来自v-c的所有转换器
mapperFactory.classMap(A.class, B.class)
.customize(new AentityBdtoConverter()).register();
return mapperFactory.getMapperFacade();
}
}
错误原因如下:
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):
<dependency>
<groupId>c.s.r</groupId>
<artifactId>v-c</artifactId>
<version>0.0.11</version>
</dependency>
The v-c jar contains a spring-devtools.properties
properties file in the src/main/resources/META-INF directory
restart.include.orika=/orika-core.*\.jar
And Orika dependency is declared in the v-c pom :
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.5.4</version>
</dependency>
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<A, B>
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 :
import c.s.r.commun.converter.AentityBdtoConverter;
@Configuration
public class OrikaConfiguration {
@Bean
public MapperFacade mapperOrika() {
final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
// adding all of my converters from v-c the same way as below
mapperFactory.classMap(A.class, B.class)
.customize(new AentityBdtoConverter()).register();
return mapperFactory.getMapperFacade();
}
}
The cause error is :
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
专注分享java语言的经验与见解,让所有开发者获益!
评论