快速搭建SpringBoot

项目中引入依赖

    <!-- 引入了父Maven项目 ,继承父Maven项目所有的配置信息

    spring-boot-starter-parent 又引入一个父Maven项目
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.3.5.RELEASE</version>
  </parent>
  spring-boot-dependencies  帮我们管理了SpringBoot应用中所有的依赖的版本,
  以后我们导入已有依赖就不需要写版本号了,它帮我们解决第三方库直接的版本冲突问题
  名次:SpringBoot的版本仲裁中心
    -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.5.RELEASE</version>
    </parent>

    <!--
        starter 场景启动器:不同的场景启动器维护了所对应的所有依赖,从而简化maven文件书写
        spring-boot-starter-web:使用Spring MVC构建Web(包括RESTful)应用程序。
            使用Tomcat作为默认的嵌入式容器
    -->
    <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>

建包并创建控制器

@RestController   // @Controller +@ResponseBody
@RequestMapping("/hello")
public class HelloController {

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

编写启动类 

@SpringBootApplication // 标记成Springboot的启动类
public class Application {

    public static void main(String[] args) throws IOException {
        SpringApplication.run(SpringApplication.class,args);
    }
  
}

修改端口

如果出现 Web server failed to start. Port 0 was already in use. 说明端口正在使用,我们需要修改默认端口
server.port=8088

部署服务器

<!--部署springboot的插件, 只有加了这个插件 当运行 java -jar xxxx.jar 才能正常启动-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

将这个应用打成jar包,直接使用java -jar的命令进行执行;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值