1.新建springboot项目,详情查看使用IDEA搭建一个简单的SpringBoot项目——详细过程_君当自强-优快云博客_springboot项目搭建
2.搭建过程中遇到的问题如下:
@RunWith(SpringRunner.class)
@MapperScan("com.example.test")
@ComponentScan(value = "com.example.test.serviceImpl")
@SpringBootTest(classes= DemoApplication.class)
public class TestApplicationTests
springboot测试启动类不加@RunWith(SpringRunner.class),service注入不进去
不加MapperScan包扫描不到
@SpringBootApplication @MapperScan("com.example.test.mapper")
public class DemoApplication
启动类目录位置需要高于controller,不然扫描不到controller
spring:
datasource:
name: mysql
url: jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: root
password: 123
driver-class-name: com.mysql.jdbc.Driver
URL上不加serverTimezone
报错 The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.
springboot内置tomcat端口为8080,访问路径为localhost:8080
本文详细介绍了如何使用IDEA创建SpringBoot项目,包括配置SpringBootTest、MapperScan、ComponentScan等注解,以及解决启动类位置、数据库连接和时区设置等问题。在搭建过程中,需要注意SpringRunner类用于测试,MapperScan用于扫描Mapper接口,ComponentScan指定服务实现类包,数据库URL需包含正确时区设置,否则可能导致错误。此外,还提到SpringBoot默认端口为8080。
808

被折叠的 条评论
为什么被折叠?



