Spring context compilation time check

Is there any maven tool or plugin that can check Spring context at compile time or during maven build execution?

I understand that it is not trivial to check that the context is completely correct without starting the application, but it will be useful to check some trivial cases, for example, if you define a bean context in xml and then the bean class must be present in the classpath.

+4
source share
1 answer

Each Spring Guide contains such a performance test.

Spring MVC MockMvc. , Spring , URL- + Spring. maven.

- :

@WebAppConfiguration
@ContextConfiguration(classes = RestApplication.class)
public class RestApplicationContextTest extends
    AbstractTestNGSpringContextTests {

  private static final String FULL_USER_URL = "http://localhost:10403/users";
  private MockMvc mockMvc;

  @Autowired
  private WebApplicationContext webApplicationContext;

  @BeforeMethod
  public void init() {
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
  }

  private static String createTestRecord(int identifier) {
    String testingRecordString =
        "{\"email\": \"user%d@gmail.com\", \"name\": \"User%d\"}";
    return String.format(testingRecordString, identifier, identifier,
        identifier);
  }

  @Test
  public void testPost() throws Exception {
    // GIVEN
    String testingRecord = createTestRecord(0);

    // WHEN
    // @formatter:off
    MvcResult mvcResult = mockMvc.perform(post(FULL_USER_URL)
        .contentType(MediaType.APPLICATION_JSON)
        .content(testingRecord))
        .andReturn();
    // @formatter:on

    // THEN
    int httpStatus = mvcResult.getResponse().getStatus();
    assertEquals(httpStatus, HttpStatus.CREATED.value());
  }
  ...
+3

Source: https://habr.com/ru/post/1608863/


All Articles