The first application of idea+Spring Boot, and the configuration of hot deployment

(1) Create a project, use spring boot, and configure maven.
By default

Fill in the project information

The following is to choose some dependent JAR packages. If you develop a web project, the web package must be imported. Others, such as databases or templates, depend on individual circumstances. If you just want to play a demo and don't involve database development, then don't import dependencies such as Mybatis, otherwise it will prompt you to configure the database information before running.
write picture description here

The following is the simple code of our project, which is to get a controller, which is equipped with a function to map the path.
write picture description here

(2) The following is the configuration of hot deployment. Hot deployment means that after you modify some code, save it, you can directly refresh the browser to see the effect, you no longer need to restart the server to re-run, although we re-run a button for a few seconds, but the project is big Not just seconds. There are mainly 4 places that need to be configured.

- Add SDK dependencies in POM.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>

- add maven startup plugin

<plugin>
    <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <fork>true</fork>
    </configuration>
</plugin>

--idea also needs to be set to be able to be automatically compiled in pairs. Ctrl+Shift+A, search build project automatically, enter the setting interface, you can open the setting interface by yourself without searching, and then find the corresponding option. Check it.
write picture description here

——Continue the shortcut key search Registry, open the interface, and find the following option, which literally means the setting that allows the program to be automatically compiled at runtime. Check it.
write picture description here

Then, it worked.

(3) The use of the database. used here MySQL. First, configure the dependent jarpackages and add the following. If there are no special requirements, maven repositoryfind the version with the most users in it:

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.39</version>
</dependency>

Then it is to configure the data source. Here the official website gives it by default application.properties, but the writing and prompting are not very friendly. spring bootPeople prefer to use application.ymlit in it. As you can see, just change the suffix of the original file, and then we are in This file writes the configuration of the data source:

spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/xxx
    username: xxx
    password: xxx
    driver-class-name: com.mysql.jdbc.Driver

That's it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325826524&siteId=291194637