Skip to content

Commit f57604b

Browse files
authored
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
1 parent c253eb6 commit f57604b

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.requestmappingvalue;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
@RestController
8+
@RequestMapping("/${request.value}")
9+
public class WelcomeController {
10+
11+
@GetMapping
12+
public String getWelcomeMessage() {
13+
return "Welcome to Baeldung!";
14+
}
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
server.servlet.context-path=/spring-mvc-basics
2+
request.value=welcome
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.requestmappingvalue;
2+
3+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
4+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
5+
6+
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.test.web.servlet.MockMvc;
11+
12+
@SpringBootTest
13+
@AutoConfigureMockMvc
14+
class WelcomeControllerUnitTest {
15+
16+
@Autowired
17+
private MockMvc mockMvc;
18+
19+
@Test
20+
public void whenUserAccessToWelcome_thenReturnOK() throws Exception {
21+
this.mockMvc.perform(get("/welcome"))
22+
.andExpect(status().isOk());
23+
}
24+
25+
}

0 commit comments

Comments
 (0)