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:
Pablo Aragonés López 2022-05-17 21:02:03 +02:00 committed by GitHub
parent c253eb6bd8
commit f57604bef0
3 changed files with 41 additions and 0 deletions

View File

@ -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!";
}
}

View File

@ -1 +1,2 @@
server.servlet.context-path=/spring-mvc-basics
request.value=welcome

View File

@ -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());
}
}