飞道的博客

第一个springBoot maven 项目

284人阅读  评论(0)

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 


转载:https://blog.csdn.net/lc19920727/article/details/127835899
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场