Spring Boot is a new framework provided by the Pivotal team. It is designed to simplify the initial construction and development process of new Spring applications. The framework uses an ad hoc approach to configuration, eliminating the need for developers to define boilerplate configurations.
The operating environment of this tutorial: windows7 system, java10 version, DELL G3 computer.
Spring Boot is a new framework provided by the Pivotal team. It is designed to simplify the initial construction and development process of new Spring applications. The framework uses an ad hoc approach to configuration, eliminating the need for developers to define boilerplate configurations. To understand it in my own words, Spring Boot is actually not a new framework. It configures the use of many frameworks by default, just like Maven integrates all Jar packages and Spring Boot integrates all frameworks.
Build services faster and more conveniently, greatly saving workload, as follows:
1) Configure web.xml and load it Spring and Spring mvc
2) Configure database connection and configure Spring transaction
3) Configure reading of loaded configuration files and enable annotations
4) Configuration log file
...
After the configuration is completed, deploy Tomcat for debugging. It may be necessary for even a small function, so it is really troublesome to do it all over again! ! !
The introduction of springboot will make it a thing of the past
There are many ways to build it, with Idea Introduction to building a project
1. Select File -> New —> Project... A box to create a new project will pop up
There are two modules by default in the pom.xml file: spring-boot-starter: core module, including automatic configuration support, logging and YAML; spring-boot-starter-test: test module, including JUnit, Hamcrest, Mockito. 2. Write controller contentorg.springframework.boot spring-boot-starter-web
@RestController public class HelloWorldController { @RequestMapping("/hello") public String index() { return "Hello World"; } }@RestController means that all methods in the controller are output in json format, so there is no need to write any jackjson configuration! 3. Start the main program, open the browser and visit http://localhost:8080/hello, and you can see the effect. It is very simple! How to do unit testing Open the test entrance under src/test/, write a simple http request to test; use mockmvc, and use MockMvcResultHandlers.print() to print out the execution results.
@RunWith(SpringRunner.class) @SpringBootTest
public class HelloWorldControlerTests { private MockMvc mvc; @Before public void setUp() throws Exception { mvc = MockMvcBuilders.standaloneSetup(new HelloWorldController()).build(); } @Test public void getHello() throws Exception { mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()) .andReturn(); } }Debugging of development environment Hot start is already very common in normal development projects. Although in the process of developing web projects, an error is always reported when starting and restarting the project; but Spring Boot does Debugging support is very good, and modifications can take effect in real time. You need to add the following configuration:
This module will be disabled when running in a complete packaging environment. If you launch the application using java -jar or a specific classloader, it will consider this a "production environment". Summary Using Spring Boot can build projects very conveniently and quickly, so that we don’t have to worry about the compatibility between frameworks, applicable versions and other issues. We want to use anything, just add One configuration is enough, so using Spring Boot is very suitable for building microservices. Recommended related video tutorials:org.springframework.boot spring-boot-devtools true org.springframework.boot spring-boot-maven-plugin true
The above is the detailed content of How to understand the springboot framework. For more information, please follow other related articles on the PHP Chinese website!