2016-08-23 11 views
0
@RunWith(SpringRunner.class) 
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ServerApplication.class) 
public class ExampleTest { 
    public static final String EXAMPLE = "/example"; 

//this is the TestRestTemplate used 
    @Autowired 
    TestRestTemplate testRestTemplate; 

//this is the test 
    @Test 
    public void testExample() { 
     String s = "asd"; 
     Object response = testRestTemplate.postForEntity(EXAMPLE, s, String.class ,Collections.emptyMap()); 
    } 
} 

を送信しません:TestRestTemplate postForEntityこれはテストエンドポイントであるrequestbody春ブーツ1.4に

@RestController 
public class ServerController { 

    @ResponseBody 
    @PostMapping("/example") 
    public String exampleEndpoint (String in) { 
     return in; 
    } 
} 

@SpringBootApplication 
@ComponentScan("com.company.*") 
public class ServerApplication { 

など 私はそれをデバッグする場合、exampleEndpointでパラメータで常にnullです。 私は私はそれはそれだけであること、それがエンドポイントを打つという意味で動作しますが、名前を変更し、すべての会社のものを削除し、それ以外は、これはそれがどのようにある春ブーツ1.4春4.3.2

を使用していますリクエストは通過しません。あなたがそうのようなRequestBodyであなたの方法exampleEndpointに引数に注釈を付ける必要がある

答えて

1

public String exampleEndpoint (@RequestBody String in) { 
     return in; 
    } 
+0

おかげで、それはそれでした。 – Peter

関連する問題