我試圖讓JSR-311 plugin與Grails 2.3.7一起工作。我使用0.10版本,因爲我認爲0.11需要Grails 2.4。新澤西州子資源定位器錯誤
我已使用generate-resource
命令爲我的域類Product
創建一個端點。創建兩個資源類別,ProductCollectionResource
和ProductResource
。我已經調整了他們一點,但基本上是這樣的:
ProductCollectionResource
@Path('/api/products')
@Consumes(['application/json'])
@Produces(['application/json'])
class ProductCollectionResource {
def productResourceService
@Path('{id}')
@GET
ProductResource getResource(@PathParam('id') Long id) {
new ProductResource(productResourceService: productResourceService, id:id)
}
@GET
Response readAll(@QueryParam("max") Integer max, @QueryParam("offset") Integer offset) {
ok productResourceService.readAll(max, offset)
}
}
ProductResource
@Consumes(['application/json'])
@Produces(['application/json'])
class ProductResource {
def productResourceService
def id
@GET
Response read() {
ok productResourceService.read(id)
}
}
在ProductCollectionResource
的readAll
方法工作正常 - 當我打它,我回來的產品列表,但是當我嘗試訪問一個特定的產品的ID(在/api/products/123
),我得到以下錯誤:
Caused by MessageException: A message body writer for Java class com.myapp.ProductResource, and Java type class com.myapp.ProductResource, and MIME media type application/json was not found
->> 285 | write in com.sun.jersey.spi.container.ContainerResponse
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1479 | _handleRequest in com.sun.jersey.server.impl.application.WebApplicationImpl
| 1391 | handleRequest . . in ''
| 1381 | handleRequest in ''
| 416 | service . . . . . in com.sun.jersey.spi.container.servlet.WebComponent
| 538 | service in com.sun.jersey.spi.container.servlet.ServletContainer
| 716 | service . . . . . in ''
| 193 | process in org.grails.jaxrs.web.JaxrsContext$JaxrsServiceImpl
| 45 | handle . . . . . . in org.grails.jaxrs.JaxrsController
| 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 150 | invoke in net.bull.javamelody.JspWrapper
| 285 | invoke . . . . . . in net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler
| 198 | doFilter in net.bull.javamelody.MonitoringFilter
| 176 | doFilter . . . . . in ''
| 67 | doFilter . . . . . in ''
| 53 | doFilter in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 82 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 63 | doFilter . . . . . in com.odobo.grails.plugin.springsecurity.rest.RestLogoutFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 82 | doFilter . . . . . in com.brandseye.cors.CorsFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
所以它看起來像它試圖馬歇爾我ProductResource
類JSON,我認爲這是不是真的我想要的。我認爲它應該調用ProductResource.read()
方法,並將返回的值從該方法編組爲JSON。
輝煌的文件,即工作。謝謝! – rcgeorge23