获取404未找到 - 使用Jersey + ExtJS访问有效的REST服务 [英] Getting 404 Not Found - while accessing valid REST service with Jersey + ExtJS
问题描述
我正在使用ExtJS,需要访问REST服务。我试着用Spring的MVC REST支持功能,并且工作得很好。
I am working on ExtJS and need to access the REST services. I tried doing that with Spring's MVC REST supporting functionality and it worked well.
现在我必须用Jersey(JAX-RS)来强制它。当尝试与泽西,我不断得到404错误。我认为注释,URL映射等是好的(因为类似的工作在Spring)
Now its kind of mandatory that I have to go with Jersey(JAX-RS). When tried with Jersey, I keep getting 404 error. I think the annotations, URL mapping, etc are fine (since the similar ones worked for Spring)
下面是相关的代码段。
Below are the relevant code snippets.
Web.xml
<servlet>
<servlet-name>spring-jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.myProducts.controller</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-jersey</servlet-name>
<url-pattern>/jersey/*</url-pattern>
</servlet-mapping>
App.js
Ext.onReady(function() {
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
autoSync: true,
model: 'Product',
proxy: {
type: 'rest',
url: 'products',
format: 'json',
headers: {
'Content-Type': 'application/json'
},
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json'
},
api: {
create: 'products/createJ/',
read: 'products/readJ/',
update: 'products/editJ/',
destroy: 'products/deleteJ/'
}
}
});
控制器:
@Component
@Path("products/jersey/products")
public class JerseyProductsController {
@Autowired
private ProductService productService;
@POST
@Path("createJ/{id}")
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
public Product createJ(@PathParam("id") int id, @RequestBody Product myProduct) {
myProduct.setId(id);
return productService.create(myProduct);
}
@PUT
@Path("editJ/{id}")
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
public Product editJ(@PathParam("id") int id, @RequestBody Product myProduct) {
myProduct.setId(id);
return productService.update(myProduct);
}
@DELETE
@Path("deleteJ/{id}")
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
public Product deleteJ(@PathParam("id") int id) {
return productService.delete(id);
}
@GET
@Path("readJ/")
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
public List<Product> allProductsJ() {
return productService.getAll();
}
}
我以下URL为404:
I get 404 for below URL:
Request URL:http://localhost:4080/MyProducts/products/jersey/products/readJ/.json?_dc=1407930853131&page=1&start=0&limit=25
Request Method:GET
Status Code:404 Not Found
请允许我知道遗漏的是什么。
Kindly let me know what is being missed.
推荐答案
不确定是什么问题,但您可以尝试以下一个:
Not sure what's the issue but you could try below one :
<url-pattern>*.do</url-pattern>
我相信它可以捕获以.do结尾的请求,它减少了头痛的一些模式在URL之间。
I believe its because it could capture requests ending with .do and it reduced the headache of having some pattern in between the URL.
这篇关于获取404未找到 - 使用Jersey + ExtJS访问有效的REST服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!