Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a project by SpringBoot

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces you how to build the SpringBoot project, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Preface

I have been using SpringBoot for more than two years. I have benefited a lot from the zero awareness of SpringBoot at the beginning to the framework that we must come into contact with in daily development. in fact, SpringBoot is an extension of Spring. In the past, we did framework integration and there were a large number of configuration files to be configured in the development process, while the emergence of SpringBoot rescued us from a large number of configuration files xml, and we no longer need to do too much bean configuration and DI configuration. After using SpringBoot, you only need to focus on the application configuration file to do simple property configuration, because SpringBoot embedded Tomcat also eliminates the trouble of installing Tomcat, we only need to run the project root directory under the startup class main method to start the project, is not compared to previous projects have a feeling of awesome plus, talk about today first, then we learn how to build a SpringBoot project from scratch.

I. installation of development tools and preparation for environmental installation

Development tool: Eclipse/IntelliJ IDEA (IDEA I use)

The development tools can be downloaded from the official website.

JAVA environment: JDK (version 1.8 I used)

JDK goes to the official website to download the window environment variable configuration tutorial.

Jar Management: Maven (my IDEA plug-in maven3)

You can also install maven and configure it in the development tool setting.

Development tools install Spring help plug-in 1.Eclipse install Spring Tools4 plug-in

Since I am using the IntelliJ IDEA development tool, I will not go into details here.

2.IntelliJ IDEA installs the Spring Assistant plug-in

Open IDEA and click "File- > Setting- > plugins" in the menu bar to open the plug-in window.

Search for "spring" or "Spring Assistant" enter in the plug-in window and find the following figure for Install installation. (I have already installed it, so the button is Uninstall)

Restarting IDEA takes effect.

Third, set up the SpringBoot project 1. Create a project using the plug-in "Spring Assistant" in IDEA.

The ① menu bar "file- > new- > project" opens the create project window.

③ changes according to your own needs, next.

⑤ Finish .

② can see from the ① diagram that it is easy to create a SpringBoot project.

Maven project pom.xml joins springboot dependency

Org.springframework.boot spring-boot-starter-parent 2.3.4.RELEASE. Org.springframework.boot spring-boot-starter-web

Create the startup class DemoApplication.java. Note that the startup class must be created in the code root directory, otherwise adding other code will start the error report.

Package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @ SpringBootApplication public class DemoApplication {public static void main (String [] args) {SpringApplication.run (DemoApplication.class, args);}}

Application configuration file, which can put some properties used by the project.

Change the project startup port, project global path, and so on.

We can create a Controller controller with the @ RestController annotation, add a test method to the controller, and add @ GetMapping ("/ test")

Package com.example.demo.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @ RestController public class DemoController {@ GetMapping ("/ test") public String test () {return "Hello World";}}

After the project has been created, start to see the actual effect, right-click the DemoApplication.java class and start Run 'DemoApplication' or Debug' DemoApplication'.

Today's creation is to use plug-ins to help us create a SpringBoot project, in fact, we can first create a maven project, and then pom.xml add dependencies, create Application.java startup classes (with @ SpringBootApplication annotation, main method), add application configuration files, and finally create the simplest springboot project.

On how to build the SpringBoot project to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report