This is a simple Spring application to introduce someone to Spring. Each commit adds additional features to the project.
- create application with the initializer
- dependencies: Spring Web
- Resources
DemoApplicationJava@SpringBootApplication- short for
@Configuration&@EnableAutoConfiguration&@EnableWebMvc&@ComponentScan @ComponentScan--> look for other components, configurations, and services, looks in the current package, this finds the HelloWorldController
- short for
HelloWorldController@RestController- alternative for
@Controller&@ResponseBody - https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestBody.html
- uses https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/converter/HttpMessageConverter.html in behind
- alternative for
@GetMapping- short for
@RequestMapping(method=GET)
- short for
HelloWorldController@SpringBootTest- look for
@SpringBootApplicationand use that to start a Spring application context
- look for
@AutoConfigureMockMvc- does not start the server, but will be processed same as if the server was started.
- alternative inject TestRestTemplate class to make a request to a running server
- Resources
Movie@Entity-> JPA Annotation to mark as entity
MovieRepositoryCrudRepository-> implements all Crud functions- function name is parsed there is also something possible like: findByNameAndReleaseDate(String name, LocalDate releaseDate)
MovieController- similar to
HelloWorldController - can be removed by adding the following to the repository:
@RepositoryRestResource(collectionResourceRel = "people", path = "people")from org.springframework.boot:spring-boot-starter-data-rest
- similar to
MovieRepositoryTest@DataJpaTest-> creates an inmemory DB that allows us to also test queries
- MovieControllerTest
@MockBeancreates a mock of the repository- similar to
HelloWorldController
- Resources