# Spring boot

## Application Runner <a href="#application-runner" id="application-runner"></a>

```java
@Slf4j
public class MyApp implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) {
        String username = getValueOrDefault(args, "username", propertyUsername);
        String password = getValueOrDefault(args, "password", propertyPassword);
        String projectUrl = getValueOrDefault(args, "projectUrl", propertyProjectUrl);

        log.info("Using username={}, password={}, projectUrl={}", username, password, projectUrl);
    }

        protected String getValueOrDefault(ApplicationArguments args, String commandLineKey, String defaultValue) {
        if (args.containsOption(commandLineKey) && !args.getOptionValues(commandLineKey).isEmpty()) {
            return args.getOptionValues(commandLineKey).get(0);
        }
        return defaultValue;
    }
}
```

## Test web service <a href="#test-web-service" id="test-web-service"></a>

```java
@RunWith(SpringRunner.class)
@WebMvcTest(Controller.class)
public class ControllerUTest {
    @Autowired private MockMvc mockMvc;
    @MockBean private MoveService moveService;
    @MockBean private StartService startService;

    @Test
    public void testMove() throws Exception {
        when(moveService.move(any(BattleSnakeRequest.class)))
            .thenReturn(MoveResponse.builder().move(MOVE.UP)
                .build());
        this.mockMvc
            .perform(
                post("/move")
                    .contentType(MediaType.APPLICATION_JSON)
                    .characterEncoding("UTF-8")
                    .content(getContent("move-request.json"))
            )
            .andExpect(status().isOk())
            .andExpect(content().json("{\"move\":\"up\"}"))
        ;
    }    
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.null-pointer.co.uk/spring-boot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
