0

I am getting this error when i run my spring boot Application. Can anyone tell me how to fix it?

my SpringBoot project is based on Groovy and Gradle.

the error massage is like below

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

I have no metaClass field in class(com.myapp.Orders). The class(com.myapp.Orders.groovy) is like below

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

the destination class(com.myapp.AfOrders.groovy) is like below

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

my build.gradle is like below

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')

}

my config file is below

<?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>
SpaceNet
  • 193
  • 2
  • 18
  • A few issues seem to mention checking your dozer mapping file for typos etc e.g. https://stackoverflow.com/questions/14783315/org-dozer-mappingexception-no-read-or-write-method-found-for-field – Mike W Apr 22 '18 at 08:15
  • Just to have it asked and rule out those battling over fields: why are you mixing Lombok and Groovy? Your example code there is basically the same in Lombok and Groovy (and you don't need `def String x`, just `String x` is fine) – cfrick Apr 22 '18 at 08:19
  • @cfrick I'm using Lombok because this is spring boot application, and I don't want to write getter and setter method instead of @ Data. I changed @ Data to @ Getter and @ Setter, but still have same error – SpaceNet Apr 22 '18 at 08:28
  • thanks @cfrick , I deleted def from def String x. but still same error – SpaceNet Apr 22 '18 at 08:29
  • @Mike I think it's groovy issue(GroovyCastException), not typos. but I don't find out why this happens. – SpaceNet Apr 22 '18 at 08:35
  • I have no field called "metaClass" in the groovy class. – SpaceNet Apr 22 '18 at 08:36
  • You should remove the “one-way” attribute from the exclude. Since it only excludes when going from class A to class B. But you’re going the other way. Also using Lombok’s `@Getter` and `@Setter` annotations with groovy is redundant since Groovy generates getters and setters automatically. – Strelok Apr 22 '18 at 14:25
  • But Groovy already generates the getters and setters for you. Lombok brings some of the AST transformations, that Groovy applies automatically back to Java -- there is hardly any need for Lombok, if you use Groovy and the error about metaClass you get there is a strong indicator for that. – cfrick Apr 23 '18 at 04:55
  • thank you @Strelok and @ cfrick – SpaceNet Apr 23 '18 at 08:05

1 Answers1

0

I removed "one-way", it works!

SpaceNet
  • 193
  • 2
  • 18