SpringBoot学习笔记——用springboot简单搭建新应用

最近在搞一个项目,摒弃了公司老套的框架模式, 采用了springboot搭建新应用。看到如此简洁的代码 , 深受诱惑。趁周末闲余之时, 打开了b站,跟着动力节点的视频学起了springboot

视频资源

https://www.bilibili.com/video/BV1XQ4y1m7ex

简单粗暴的, 搭建个应用run起来 . 本文不介绍细节, 后续会深入了解springboot,剖析源码

一、搭建一个maven模块工程

1、父工程

 mvn archetype:generate -DgroupId=com.springboot.demo -DartifactId=demo -DarchetypeArtifactId=maven-archetype-site-simple -DinteractiveMode=false

2、子工程client端

mvn archetype:generate -DgroupId=com.springboot.demo -DartifactId=demo-client -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

3、子工程server端

mvn archetype:generate -DgroupId=com.springboot.demo -DartifactId=demo-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false 

二、springboot的引入

添加springboot 的父pom配置


      org.springframework.boot
      spring-boot-starter-parent
      1.3.0.RELEASE
 

    
      
        
        org.springframework.boot
        spring-boot-dependencies
        1.3.0.RELEASE
        pom
        import
      
    

要添加springboot构建的web 子工程, pom只需配置


      org.springframework.boot
      spring-boot-starter-web

pom加入这些配置后, 可以自动依赖内嵌的tomcat 和 spring-mvc了  ,  从而支持了web开发

三、定义springboot的主类(启动tomcat)

@RestController
@EnableAutoConfiguration
public class Application {

    @RequestMapping("/")
    public String index() {
        return "hello, spring boot";
    }
    
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

@EnableAutoConfiguration : 表明了这个类是springboot的主类。 可以看到启动入口就是main函数了。赶紧跑下看看, 可以访问  http://localhost:8080/  可以看到页面输入

hello, spring boot

截止到这里,我们就完成了一个简单的springboot工程搭建。

你可能感兴趣的:(SpringBoot,spring,boot,java,spring,后端,架构)