1.spring-boot2 ------hello world

说明: 对于spring boot项目可以利用Spring Initializr,可以更简单

spring boot系列版本为2.0.4

  1. idea新建项目: file ->new project ->Spring Initializr ->设置项目 ->选择Web ->Finish
  2. Edit Configurations设置执行spring boot main.
  3. 执行spring boot main.
  4. 相关pom文件,如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <groupId>berg.study.hello</groupId>
   <artifactId>hello-spring-boot</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

   <name>hello-spring-boot</name>
   <description>init project,hello world</description>
    <!-- lookup parent from repository -->
   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.0.4.RELEASE</version>
      <relativePath/>
   </parent>

   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      <java.version>1.8</java.version>
   </properties>

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

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

5. 通过mvn clean package -Dmaven.test.skip=true,获得对应的jar包,如: hello-spring-boot-0.0.1-SNAPSHOT.jar,

则 java -jar hello-spring-boot-0.0.1-SNAPSHOT.jar 来启动.

6.若配置相关controller,则可以通过localhost:8080/****来访问

猜你喜欢

转载自blog.csdn.net/snail_Bao/article/details/81487126