在IDEA部署SpringBoot服务器

目录

一、前言

二、修改pom.xml

​编辑

三、编写启动主程序

​编辑

四、创建Controller

​编辑

四、运行

总结


一、前言

前提:IDEA、JDK

创建好Maven项目

二、修改pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
    </parent>





        <!-- web starter, 自动配置SpringMVC,内置tomcat -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

三、编写启动主程序

package com.iflytek;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.iflytek.dao")
public class Application {
public static void main(String[] args) {

    SpringApplication.run(Application.class, args);
    }
}

四、创建Controller

package com.sodaopen.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello(){
return "Hello, Spring Boot";
}
}

四、运行

1.运行主程序(效果图):

2.在浏览器中输入TomCat网址:

http://localhost:8080/hello

最终运行效果:

 

总结

         部署完成SpringBoot项目后,后续便可以继续构建更多Spring程序了。

SpringBoot项目在与其他的项目部署在一起时,SpringBoot主程序启动有可能会失败,常见的原因是在pom文件中的其他依赖可能会与SpringBoot的依赖冲突,解决方法:在新的项目重新部署Spring项目,或者将其他无关依赖先注释掉。

猜你喜欢

转载自blog.csdn.net/weixin_61569821/article/details/128330724