SpringBoot环境配置以及springboot-first

SpringBoot

  • spring.io

环境部署

环境准备

  1. maven3.3+
  2. jdk1.8
  3. Idea 2019+
  4. springboot2.4

配置maven

  • 阿里源
    <mirror>
    <id>aliyunmaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>https://maven.aliyun.com/repository/public </url>
    </mirror>
  • JDK版本
        <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>

第一个hello springboot

创建一个maven项目并且新建model

修改tx_sboot的pom.xml文件

<!--  springboot starter的父类包-->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.0</version>
  </parent>
  <dependencies>
    <dependency>
      <!--  springboot starter web相关的包-->
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
<!--        关于封装jar包相关的包-->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

在../springboot-frist/src/main/java下建立class文件TestControler

package cn.tx.sboot;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestControler {

  @RequestMapping("hello")
  public String Hello(){
    return "hello springboot";
  }


}

在../springboot-frist/src/main/java下建立class文件FirstSpringApplication

package cn.tx.sboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

运行主函数

运行成功查看localhost:8080/hello

封装jar包

mvn -f springboot-first/ clean package

运行jar包

java -jar springboot-first/target/springboot-first-1.0-SNAPSHOT.jar

运行成功

posted @ 2020-11-27 14:14  Ai577  阅读(69)  评论(0)    收藏  举报