美文网首页程序员
快速构建基于SpringBoot的Web工程(1)

快速构建基于SpringBoot的Web工程(1)

作者: d9bc67141c29 | 来源:发表于2017-05-26 10:44 被阅读0次

1. 利用maven生成web目录结构

  • groupId:com.demo
  • artifactId:demo

mvn archetype:generate -DgroupId=com.demo -DartifactId=demo -DarchetypeArtifactId=maven-archetype-webapp

2. 添加SpringBoot最基本依赖

spring-boot-dependencies ** 是一个pom集合包涵了 所有SpringBoot所需要的jar包 指定这个集合的版本后 后面包含在这个pom集合中的依赖都不需要指定版本 详见:spring-boot-dependencies**

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

3. 添加启动类

@EnableAutoConfiguration//启用自动配置
@ComponentScan//组件扫描
@RestController
public class ApplicationStart {
    public static void main(String[] args) {
        SpringApplication.run(ApplicationStart.class, args);
    }
    @RequestMapping("/")
    public String init(){
        return "Hello World";
    }
}

执行main方法直接启动,SpringBoot内置Tomcat容器

Paste_Image.png

相关文章

网友评论

    本文标题:快速构建基于SpringBoot的Web工程(1)

    本文链接:https://www.haomeiwen.com/subject/fvitfxtx.html