Spring-boot: Unable to resolve class groovy.json.JsonSlurper

Created on 7 Apr 2017  路  1Comment  路  Source: spring-projects/spring-boot

To recreate, put the following in a file, say bug.groovy

@RestController
class Bug {

    @RequestMapping("*")
    String home() {
        new groovy.json.JsonSlurper()
        "!"
    }

}

Run it:

spring run bug.groovy 
startup failed:
file:/Users/curt.cox/tmp/spring-boot/bug.groovy: 6: unable to resolve class groovy.json.JsonSlurper 
 @ line 6, column 6.
        new groovy.json.JsonSlurper()
        ^

1 error

When writing groovy scripts, all of the standard groovy classes should be available. If you delete the line creating JsonSlurper, the application runs as expected.

invalid

Most helpful comment

JSONSlurper is in groovy-json which isn't on the classpath by default. If you want to use it, you can use @Grab:

@Grab("org.codehaus.groovy:groovy-json")
@RestController
class Works {

    @RequestMapping("*")
    String home() {
        new groovy.json.JsonSlurper()
        "!"
    }

}

There's no need for a version as Spring Boot's dependency management will take care of that for you.

>All comments

JSONSlurper is in groovy-json which isn't on the classpath by default. If you want to use it, you can use @Grab:

@Grab("org.codehaus.groovy:groovy-json")
@RestController
class Works {

    @RequestMapping("*")
    String home() {
        new groovy.json.JsonSlurper()
        "!"
    }

}

There's no need for a version as Spring Boot's dependency management will take care of that for you.

Was this page helpful?
0 / 5 - 0 ratings