标签:自动配置 test pos inf root control port auto 数据库连接
由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决
解决方案1:
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
//@SpringBootApplication
@MapperScan("com.example.*") //扫描:该包下相应的class,主要是MyBatis的持久化类.
解决方案2:
#去配置文件中配置数据库连接参数
########################################################
###datasource -- mysql\u7684\u6570\u636e\u5e93\u914d\u7f6e.
########################################################
spring.datasource.url = jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.max-active=20
spring.datasource.max-idle=8
spring.datasource.min-idle=8
spring.datasource.initial-size=10
热启动占用端口报错
解决方案1:
#在配置文件中修改端口号
server.port=8888
解决方案2:
选择另外一种热启动方式,或者关闭端口
扫描包的注解 @MapperScan 和 @ComponentScan 的区别
首先,@ComponentScan是组件扫描注解,用来扫描@Controller @Service @Repository这类,主要就是定义扫描的路径从中找出标志了需要装配的类到Spring容器中
其次,@MapperScan 是扫描mapper类的注解,就不用在每个mapper类上加@MapperScan了
这两个注解是可以同时使用的。
@SpringBootApplication
//扫描:该包下相应的class,主要是MyBatis的持久化类.
@MapperScan("com.example.mapper")
//扫描controller、service等
@ComponentScan(basePackages = { "com.example.controller", "com.example.service"})
标签:自动配置 test pos inf root control port auto 数据库连接
原文地址:https://www.cnblogs.com/renxiuxing/p/9762019.html