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

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容