由于新的项目需要,新项目不再使用php开发,采用java语言开发。今天重新搭建尝试搭建spring boot项目,使用的开发工具是IntelliJ IDEA,用maven管理包,mybatis做持久层,综合起来大体的架构和技术选型是spring boot+mybatis+maven+mysql
创建完成项目后,主要的几个文件和类如下:
项目入口的类CaseManageApplication.class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CaseManageApplication {
public static void main(String[] args) {
SpringApplication.run(CaseManageApplication.class, args);
}
}
maven的pom.xml
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
测试controller类:
/**
* @Author: kewin.cheng
* @Date: 10/12/19 9:59 AM
*/
@RestController
@RequestMapping("test/")
public class TestController {
@RequestMapping("index")
public String index() {
return "hello world!";
}
}
配置application.properties文件,配置下端口
server.port=8080
执行main主类,响应日志显示直接退出如下:
Process finished with exit code 0
预期效果是项目执行成功,可以通过http://127.0.0.1:8080/test/index访问项目返回hello world,但是系统直接退出
为什么创建spring boot的demo项目执行不成功,问题出现在这个配置上
org.springframework.boot
spring-boot-starter-tomcat
provided
解决方案:spring boot自带了tomcat,但是要去掉provided这一行系统才会正常运行,去掉后系统成功运行再次访问http://127.0.0.1:8080/test/index返回成功