第一个springBoot maven 项目

1. env: java 11 + IntelliJ IDEA 2021.3.2 (Community Edition)

2. file->new project->Maven:

pom.xml 需要导入的包:后面三个是jdk8升级到11后,可能会出错,需要用到的包

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
    </dependency>

    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
</dependencies>

 3.编写MainApplication.java 作为启动类

@SpringBootApplication
//@ComponentScan(basePackages= "com/example/controller") 如果controller和启动类不再一个包下则需要使用组件扫描标签用于寻找,或者WhitePage error
public class MainApplication {

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

4.编写controller类:

@RestController
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String HelloController(){
        return "Hello this is hello handler 02";
    }
}

5.run main(), 测试访问地址:

http://localhost:8888/hello

6. application.properties可配置端口等信息

spring.freemarker.checkTemplateLocation=false
server.port=8888

7.打包:

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

cmd: jave -jar xxx.jar 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值