刚进公司不久按照前辈的代码自己写了个小功能但是在单元测试的时候报错了,求解

sky_boy 发布于 2017/06/30 13:46
阅读 180
收藏 0

org.springframework.web.client.HttpClientErrorException: 404 Not Found
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:264)
    at com.women.PM.JUnit.IMyProjectControllerTest.getListByCtype(IMyProjectControllerTest.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
 

加载中
0
skhuhu
skhuhu

看看请求地址对不对·····都404 

s
sky_boy
应该没错吧
s
sky_boy
//这是测试代码 String requestUrl = "http://localhost:8080/MyProject/getListByCtype/{cType}"; String result = template.getForObject(requestUrl, String.class, 1);
s
sky_boy
//这是我写的代码 @RequestMapping(value="/getListByCtype/{cType}",method=RequestMethod.GET) @ResponseBody public ControllerResult getListByCtype(@PathVariable("cType") int cType) throws Exception; //
0
skhuhu
skhuhu

http://localhost:8080/MyProject/getListByCtype/{cType}  这个请求是不对的··· 

1. http://localhost:8080/MyProject/getListByCtype/78 要么这样 

2.http://localhost:8080/MyProject/getListByCtype?id= 78 要么这样 ····

{cType} 你这样写 是什么鬼

s
sky_boy
这是我看我们师兄写的代码 仿写的 他说是引用restful设计风格 写的 我看他测试代码里也是这样写的url
返回顶部
顶部