-
Notifications
You must be signed in to change notification settings - Fork 1
Spring Boot Basics
Majeed edited this page Jan 27, 2020
·
3 revisions
This page helps you understand and get started with Spring boot basic project structure and how to get started.
Two productive ways to get the spring boot started
- Using spring initializer
http://start.spring.io- specify you packages, download the zip and import into you IDE
- Using
spring CLI- e.g: spring init --build=gradle --java-version=1.8 --dependencies=web,jpa,h2 spring-boot-h2-demo
The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes. read more
-
@Configurationtags the class as a source of bean definitions for the application context. -
@EnableAutoConfigurationtells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings. -
@ComponentScantells Spring to look for other components, configurations, and services in the hello package, allowing it to find the controllers.
The main() method uses Spring Boot’s SpringApplication.run() method to launch an application. Did you notice that there wasn’t a single line of XML? No web.xml file either. This web application is 100% pure Java and you didn’t have to deal with configuring any plumbing or infrastructure.
Besides spring can auto inject some functionality based on their availability in the application classpath:
-
@EnableWebMvc- Normally you would add @EnableWebMvc for a Spring MVC app, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath. This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet.