Dropwizard / Groovy - ERROR io.dropwizard.jersey.errors.LoggingExceptionMapper :! groovy.lang.MissingMethodException

时间:2015-07-08 22:14:13

标签: groovy jersey dropwizard jdbi

我正在尝试使用Dropwizard创建RESTful Web API。我相信我已连接并正常运行数据库。但是,每当我尝试对特定项目执行GET请求时,都会遇到错误消息:

ERROR [2015-07-08 21:55:23,867]
io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a 
request: 084335cfa9b38151
! groovy.lang.MissingMethodException: No signature of method: static
edu.oregonstate.mist.catalogapitest.db.CourseDAO.findByCrn() is 
applicable for argument types: (java.lang.Integer) values: [12345]

不完全确定,但我认为它可能是Jetty问题而不是Dropwizard问题。

下面我已经包含了我认为可能存在问题的代码。

CourseDAO.groovy

package edu.oregonstate.mist.catalogapitest.db

import edu.oregonstate.mist.catalogapitest.core.Course
import edu.oregonstate.mist.catalogapitest.mapper.CourseMapper

import org.skife.jdbi.v2.sqlobject.SqlUpdate
import org.skife.jdbi.v2.sqlobject.SqlQuery
import org.skife.jdbi.v2.sqlobject.Bind
import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper


@RegisterMapper(CourseMapper)
public interface CourseDAO extends Closeable {
    @SqlQuery("""
            SELECT *
            FROM COURSES
            WHERE CRN = :crn
            """)
    List<Course> findByCrn(@Bind("crn") Integer crn)

    @SqlQuery("""
            SELECT *
            FROM COURSES
            WHERE COURSENAME = :courseName
            """)
    List<Course> findByCourseName(@Bind("courseName") String courseName)

    void close()
}

CourseResource.groovy

package edu.oregonstate.mist.catalogapitest.resources

import edu.oregonstate.mist.catalogapitest.core.Course
import edu.oregonstate.mist.catalogapitest.db.CourseDAO

import io.dropwizard.jersey.params.IntParam

import com.google.common.base.Optional
import javassist.NotFoundException
import org.eclipse.jetty.server.Response

import javax.validation.constraints.NotNull
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.WebApplicationException
import javax.ws.rs.core.MediaType

@Path("/course")
@Produces(MediaType.APPLICATION_JSON)
class CourseResource {

    private final CourseDAO courseDAO

    public CourseResource(CourseDAO courseDAO) {
        this.courseDAO = courseDAO
    }

    @GET
    @Path('{crn}')
    public List<Course> getByCrn(@PathParam('crn') IntParam crn) {
        println(crn.get())

        final List<Course> courses = CourseDAO.findByCrn(crn.get())

        if (courses.isEmpty()) {
            throw new WebApplicationException(404)
        }

        return courses
    }

    @GET
    @Path('/name/{courseName}')
    public List<Course> getByCourseName(@PathParam('courseName') String courseName) {
        println(courseName)

        final List<Course> courses = CourseDAO.findByCourseName(courseName)

        if (courses.isEmpty()) {
            throw new WebApplicationException(404)
        }

        return courses
    }
}

最后,这里是我的回购链接的完整参考链接:https://github.com/osu-mist/catalog-api-test

谢谢!

1 个答案:

答案 0 :(得分:0)

在您的资源中,您正在尝试调用静态方法

取代

#********************************************************************
# Wrapper Java Properties
#********************************************************************
# JVM
wrapper.java.command=C:\Program Files\Java\jdk1.7.0_65\bin\java

你需要

final List<Course> courses = CourseDAO.findByCrn(crn.get())

final List<Course> courses = courseDAO.findByCrn(crn.get()) )中的c