In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "what is the role of the springboot framework", so the editor summarizes the following contents, detailed contents, clear steps, and certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the role of the springboot framework" article.
Spring Boot is a new framework provided by the Pivotal team, which is designed to simplify the initial building and development process of new Spring applications. The framework is configured in a specific way so that developers no longer need to define a templated configuration.
The operating environment of this tutorial: windows7 system, java10 version, DELL G3 computer.
1. Origin
Spring Boot is a new framework provided by the Pivotal team, which is designed to simplify the initial building and development process of new Spring applications. The framework is configured in a specific way so that developers no longer need to define a templated configuration. As I understand it, Spring Boot is not really a new framework, it defaults to the use of many frameworks, just as Maven integrates all the Jar packages and Spring Boot integrates all the frameworks.
two。 Solve the problem
Faster and more convenient to build services, greatly saving workload, as follows:
1) configure web.xml to load Spring and Spring mvc
2) configure database connection and Spring transaction
3) configure the reading of the loading configuration file and turn on the comments
4) configure log files
...
After the configuration is completed, deploying Tomcat debugging even a small function may be required. It is really troublesome to do this again!
The introduction of springboot will make it a thing of the past.
Getting started with 3.springBoot
There are many ways to build, which are introduced by Idea.
1. Select File-> New-> Project... Pop up the box for the new project
2. A similar configuration interface will appear when you choose Spring Initializr,Next, and Idea helps us do the integration.
3. After filling in the relevant contents, click Next to select the dependent package, then click Next, and finally make sure that the information is correct and click Finish.
Introduction of project structure
Using the default configuration can save a lot of configuration, and of course you can change it according to your preference.
Finally, start the Application main method, and a java project is set up!
Introduction of Web module
1. Add modules that support web to pom.xml:
Org.springframework.boot spring-boot-starter-web
There are two modules by default in the pom.xml file:
Spring-boot-starter: core modules, including autoconfiguration support, logging, and YAML
Spring-boot-starter-test: test module, including JUnit, Hamcrest, Mockito.
2. Write controller content
@ RestControllerpublic class HelloWorldController {@ RequestMapping ("/ hello") public String index () {return "HelloWorld";}}
@ RestController means that all the methods in controller are output in json format, so you don't have to write anything about jackjson configuration!
3, start the main program, open the browser to visit http://localhost:8080/hello, you can see the effect, is it very simple!
How to do unit testing
Open the test entry under src/test/, write a simple http request to test; use mockmvc to do it, and print out the execution result using MockMvcResultHandlers.print ().
@ RunWith (SpringRunner.class) @ SpringBootTestpublic 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 ()) .a ndDo (MockMvcResultHandlers.print ()) .andReturn ();}}
Debugging of development environment
Hot start is already very common in normal development projects. Although during the development of web projects, changes to project startup and restart always report an error, Spring Boot supports debugging very well and can take effect in real time after modification. You need to add the following configurations:
Org.springframework.boot spring-boot-devtools true org.springframework.boot spring-boot-maven-plugin true
This module is disabled when running in a full packaged environment. If you launch the application with java-jar or with a specific classloader, it will consider this to be a "production environment".
The above is the content of this article on "what is the role of the springboot framework". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.