Spring Boot Web Executable Demo

1 Step by Step

  • 新建intellij project maven 项目
  • 加入pom依赖
<parent>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-parentartifactId>
    <version>1.3.5.RELEASEversion>
parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-webartifactId>
    dependency>
dependencies>
  • 新建入口类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by csophys on 16/8/31.

 */
@Controller
@EnableAutoConfiguration
public class ExecutorController {

    @RequestMapping("/")
    @ResponseBody
    public String hello(){
        return "hello world";
    }

    public static void main(String[] args) {
        SpringApplication.run(ExecutorController.class,args);
    }
}
  • 静态资源处理
resources下新建static 目录,static目录下新建index.html 文件可以默认访问到
  • 启动入口类,浏览器访问成功
  • 生成可执行的jar
1. 修改xml
加入
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>
2. 执行jar
java -jar /Users/csophys/code/downloadVoiceFileWithConnid/target/csophys-1.0-SNAPSHOT.jar

Original: https://www.cnblogs.com/csophys/p/6287992.html
Author: csophys
Title: Spring Boot Web Executable Demo

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/714235/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球