org.dozer.MappingException:没有为类中的字段(metaClass)找到读取或写入方法

时间:2018-04-22 07:03:00

标签: spring-boot gradle groovy dozer

运行Spring启动应用程序时出现此错误。 谁能告诉我如何解决它?

我的SpringBoot项目基于Groovy和Gradle。

错误按摩如下

16:18:37.215 [http-nio-9092-exec-5] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] 
- Servlet.service() for servlet [dispatcherServlet] in context with path [] 
threw exception [Request processing failed; nested exception is 
org.codehaus.groovy.runtime.typehandling.GroovyCastException: 
Cannot cast object 'org.dozer.MappingException: 
No read or write method found for field (metaClass) in class (class com.myapp.Orders)' 
with class 'org.dozer.MappingException' to class 'java.util.Map'] with root cause

我在类中没有metaClass字段(com.myapp.Orders)。 该类(com.myapp.Orders.groovy)如下所示

import lombok.Getter
import lombok.Setter
@Getter
@Setter
class Orders {
    long orderId
    String kNo
    String sOrderCode
    int orderStatus
    String deliveryTypeCode
    String receiverFullName
    Date orderAt
}

目标类(com.myapp.AfOrders.groovy)如下所示

import lombok.Getter
import lombok.Setter
@Getter
@Setter
class AfOrders {
    String kNo
    String sOrderCode
    int orderStatus
    String deliveryTypeCode
    String receiverFullName
    Date orderAt
    String fType
}

我的build.gradle如下所示

buildscript {
    ext {
        springBootVersion = '2.0.0.RELEASE'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
        maven { url 'http://jcenter.bintray.com' }
    }
    dependencies {
        classpath("io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE")
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("mysql:mysql-connector-java:5.1.45")
        classpath ("org.junit.platform:junit-platform-gradle-plugin:1.1.0")
    }
}

apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.junit.platform.gradle.plugin'

group = 'com.myapp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {

    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-data-rest')

    compile('org.springframework.boot:spring-boot-starter-web') 
    compile('org.springframework.boot:spring-boot-starter-webflux')

    compile('org.springframework.boot:spring-boot-starter-security')
    testCompile('org.springframework.security:spring-security-test')

    compile('org.flywaydb:flyway-core')
    compile('org.springframework.data:spring-data-rest-hal-browser')
    compile('org.codehaus.groovy:groovy')
    runtime('mysql:mysql-connector-java')
    compileOnly('org.projectlombok:lombok')

    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile('mysql:mysql-connector-java:5.1.45')
    runtime('mysql:mysql-connector-java:5.1.45')

    compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1')

    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1')
    compile('org.hibernate:hibernate-validator:6.0.8.Final')

    compile('net.sf.dozer:dozer:5.5.1')
    compile('net.sf.dozer:dozer-spring:5.5.1')

}

我的配置文件位于

之下
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://dozer.sourceforge.net
      http://dozer.sourceforge.net/schema/beanmapping.xsd">
    <mapping map-null="false">
        <class-a>com.myapp.Orders</class-a>
        <class-b>com.myapp.AfOrders</class-b>
        <field-exclude type="one-way"> 
            <a>metaClass</a> 
            <b>metaClass</b> 
        </field-exclude>
    </mapping>
</mappings>

1 个答案:

答案 0 :(得分:0)

我删除了“单向”,它有效!