The Springboot framework is designed to simplify the initial construction of new spring applications and the development process. The cost of simplification is that there are many rules, such as the default read configuration file name is Application.properties must be in the Config directory, the boot class scan is a peer and sub-directory. Springboot is not a new solution to existing problems, but a new experience for platform development, simplifying complex XML and other small changes in configuration information, the contract is better than the configuration.
Boot simplifies the development of spring applications, provides a modular way to import dependencies, emphasizes the ability to develop restful Web services, and provides the capability to build runnable jars, all clearly demonstrating that the boot framework is a powerful tool for developing deployable microservices.
To implement a url:http://localhost:8080/index return string: Hello world!,
Previous practice: Configure the Web. XML spring-***.xml to combine Tomcat or jetty application servers.
Spring boot notation (MAVEN project)
One, Pom.xml quote package
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Second, add controller
@RestController
public class HomeController {
@RequestMapping ("index")
Public String Index () {
Return "Hello world!";
}
}
Third, add the startup class
@SpringBootApplication
public class Appbootapplication {
public static void Main (string[] args) {
Springapplication.run (Appbootapplication.class, args);
}
}
Four, run the startup class can be
is not very simplified, the whole process is not configured with spring-related XML files. The spring version increasingly uses annotations instead of XML configurations. Default built-in spring-boot-starter-tomcat
app with default port of 8080
@RestController is an encapsulation annotation, the collection @[email protected] identifies all route methods of this class return string
@SpringBootApplication is also a package annotation, @Configuration @EnableAutoConfiguration @ComponentScan
@Configuration Identity class can use the spring IOC container as the source of the bean definition
@EnableAutoConfiguration can automatically configure the context of spring, and it will usually automatically be configured automatically based on your classpath and your bean definition.
@ComponentScan will automatically scan all classes marked with @component under the specified package and register as Bean
There are three ways of running a service
1. Run the startup class and run the main method directly
2. Use mvn spring-boot:run in the command line
3. Can generate a jar that is executed separately
Add Plugins in Pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
And then hit the jar package: MVN Packages
Execution: Java-jar Spring-boot-1.0.0-snapshot.jar can be.
Springboot Introductory One Hello world!