Target: Enter http: // localhost: 8080 / hello, get helloworld
hello.java
Package Class; Import org.springframework.boot.SpringApplication; Import org.springframework.boot.autoconfigure.SpringBootApplication; / * @SpringBootApplication annotate a main class Can not resolve org.apache.tomcat.embed: tomcat-embed -core: 8.5 .20 , indicating that the application is a SpringBoot open @SpringBootApplication, see: @Target (ElementType.TYPE {}) @Retention (RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan ( excludeFilters @Filter = {( = FilterType.CUSTOM type, classes TypeExcludeFilter.class} = { ), @Filter ( type = FilterType.CUSTOM, classes AutoConfigurationExcludeFilter.class = {} )} ) public @interface SpringBootApplication { @SpringBootConfiguration: --- SpringBoot configuration class profile configuration class is a container assembly @EnableAutoConfiguration: Open autoconfiguration @AutoConfigurationPackage: Auto the configuration package, and all of the following classes master configuration sub-packets to scan all the components inside Spring container @Import ({Registrar.class}) spring bottom notes, introduced to a container assembly Registrar.class} { @Import ({AutoConfigurationImportSelector. class}) which introduced the selector assembly will return all of the components required in the manner of the full class name of these components will be added to the vessel, introducing a lot of assembly will automatically configure the class, is introduced into the container to a desired scene All components and configure these components with automatic configuration class, eliminating the need for us to manually write the configuration inject functional components, such as working J2EE overall integration solutions and automatic configuration are spring-boot-autoconfigure-2.0.0.RELEASE in .jar in * / @SpringBootA pplication public class Hello { public static void main (String [] args) { // Spring application start up SpringApplication.run (Hello. class , args); } }
helloController.java
package Class.Control; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class helloController { @ResponseBody @RequestMapping("/hello") public String h(){ return "helloworld"; } }
pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <!--上述代码的父项目是 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.0.0.RELEASE</version> <relativePath>../../ springboot-the Dependencies </ relativePath> </parent> springboot version Arbitration Center: After we import dependence is no need to write the default version (no need to declare a natural version number which rely dependencies management) springboot-Starter-web: help us import component web module is operating normally depend spring- boot-starter: springboot scene initiator springboot all the scenes are extracted features, one made of starters (starter), these only need to introduce the items inside the starter all relevant scene introduced will depend in, use What feature is introduced into the starter what scene -> < Dependencies > < dependency > < the groupId > org.springframework.boot </ the groupId > < the artifactId > Spring-boot-starter-Web </ the artifactId > </ dependency > </ the Dependencies > <!--This plug can be packaged into an executable apply packet jar -> < Build > < plugins > < plugin > < the groupId > org.springframework.boot </ the groupId > < the artifactId > Spring-Boot-Maven-plugin </ the artifactId > < Version > 2.0.0.RELEASE </ Version > </ plugin > </ plugins > </ Build > </ Project >