Spring Boot configuration and use

Spring Boot configuration and use

1. Configuration of maven file

1. Configuration location

Configure in the settings.xml of conf under the maven file:

<mirrors>
      <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      </mirror>
  </mirrors>
 
  <profiles>
         <profile>
              <id>jdk-1.8</id>
              <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
              </activation>
              <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
              </properties>
         </profile>
  </profiles>

2. Introduce Spring Boot dependencies

1. Modify the pom.xml file

1. Stick or modify files in the pom.xml file

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>

3. Create the main program

/**
 * 主程序类
 * @SpringBootApplication:这是一个SpringBoot应用
 */
@SpringBootApplication
public class MainApplication {
    
    

    public static void main(String[] args) {
    
    
        SpringApplication.run(MainApplication.class,args);
    }
}

4. Create business code (controller)

/*
告诉控制器这是一个访问控制器
*/
@RestController
public class HelloController {
    
    

	//访问路由
    @RequestMapping("/hello")
    public String handle01(){
    
    
        return "Hello, Spring Boot 2!";
    }


}

5. The configuration file of the entire program

  1. Create application.properties file in main/resources

6. Packaged into a jar package

1. Modify the pom.xml file

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
  </build>

2. Run clean and package files

-maven-plugin



### 2. 运行clean和package文件

![在这里插入图片描述](https://img-blog.csdnimg.cn/20210323204340514.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0MjU1MTQ2,size_16,color_FFFFFF,t_70#pic_center)

Guess you like

Origin blog.csdn.net/qq_44255146/article/details/115142767