“This is the first day I participate in the August more text challenge, activity details check: August more text challenge” I am small white, pure own record master don’t waste time
SpringBoot is the use of the SPRING framework to quickly build Java EE projects can be packaged into a WAR package, run with Tomcat, can also be packaged into a JAR package with Java-jar, or directly click the run method.
Create a new project using idea as an example, select Spring Initializr and choose the default (select a startup dependency and choose a Web). It will automatically generate a XXXXApplication with annotations on it
Starting dependencies can be seen in the POM.xml file to define transition-dependent dependencies on other libraries, which together support some functionality
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Copy the code
@springBootApplication // Added annotation public class DemoApplication {! [image.png](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/801388fd3cd74dd2b2a50fac90ee8aca~tplv-k3u1fbpfcp-watermark .image) public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); }}Copy the code
Create a Controller package, for example
Public class demoController {@getMapping Public String Hello (){String STR = "hello,springBoot"; return str; }}Copy the code
OK, run it now when SpringBoot is up
The browser accesses localhost:8080
To explain what an annotation means :@SpringBootApplication is a composite annotation
If you press Ctrl to enter IDEA, you can see that there are many annotations and three key ones
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
Copy the code
So the first one I’m going to click on and you can see itA little closer to the truth is an @Configuration. So the @SpringBootConfiguration function is to indicate that it is a Configuration class, and developers can configure beans on both sides similar to the applicationContext.xml file in Spring. The second annotation @enableAutoConfiguration can be seen from the name is automatically imported configuration of the third annotation @ComponentScan open package scan OK, end hard work not overtime rush