Request Mapping value in properties file (#12226)
* Exception Handler implemented for Spring Security Resource Server * Renamed test class name to solve PMD Failure * Code formatting * Using property parameter as Request Mapping value * Renamed test class name to solve PMD Failure
This commit is contained in:
parent
c253eb6bd8
commit
f57604bef0
|
@ -0,0 +1,15 @@
|
||||||
|
package com.baeldung.requestmappingvalue;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/${request.value}")
|
||||||
|
public class WelcomeController {
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public String getWelcomeMessage() {
|
||||||
|
return "Welcome to Baeldung!";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1,2 @@
|
||||||
server.servlet.context-path=/spring-mvc-basics
|
server.servlet.context-path=/spring-mvc-basics
|
||||||
|
request.value=welcome
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.baeldung.requestmappingvalue;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
class WelcomeControllerUnitTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUserAccessToWelcome_thenReturnOK() throws Exception {
|
||||||
|
this.mockMvc.perform(get("/welcome"))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue