1.sprongboot扫描配置文件顺序优先级
- 项目路径下config文件夹下: ./config/*.yml *.properties
- 项目路径下:./*.yml *.properties
- 项目资源路径下(一般为./src/main/resources)config文件下:./src/main/resources/config/*.yml *.properties
- 项目资源路径下(一般为./src/main/resources):./src/main/resources/*.yml *.properties
2.sprongboot引入外部jar包
在代码路径下找合适的地方新建lib包,将jar导入路径下,pom.xml需要新增下面两部分
<dependency>
<groupId>随便</groupId>
<!--artifactId 随便填写-->
<artifactId>随便</artifactId>
<!--version 随便填写-->
<version>随便</version>
<!-- scope=system表示此依赖是来自外部jar,而不是maven仓库。当scope设置为system时,systemPath属性才会生效,systemPath为一个物理文件路径,来指定依赖的jar其物理磁盘的位置。 -->
<scope>system</scope>
<!-- ${project.basedir}代表根目录 -->
<systemPath>${project.basedir}/src/main/resources/lib/随便</systemPath>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
3.alter table 会导致事务直接提交
4.多模块项目 @SpringBootTest package单项目时报各种依赖找不到
需要先在父模块统一package install 后,即可单独package项目
原理是所有依赖都需要放入到本地maven仓库
5.spring boot 使用 @EnableRedisHttpSession spring.session.timeout设置无效
请详细阅读官方文档 https://docs.spring.io/spring-boot/docs/2.7.8/reference/htmlsingle/#web.spring-session
当使用 @EnableRedisHttpSession 时,这将导致自动配置退出。然后可以使用注释的属性而不是前面描述的配置属性来配置 Spring Session。
如果要用配置属性配置,需要去掉 @EnableRedisHttpSession
6.引用其他模块Dao @Mapper注解无效
1.多模块开发,引用其他模块Dao层方法是,使用@Mapper注解是无效的,需要在主main方法层使用@MapperScan注解
@SpringBootApplication(scanBasePackages = {"xxx"})
@MapperScan(basePackages = {"xxx.*.mapper"})
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class, args);
}
}
2.也可能是依赖版本问题,需要保证spring-boot-starter-parent、mybatis-spring-boot-starter两者版本兼容
7.@RequiredArgsConstructor 加onConstructor = @__(@Autowired)的区别
RequiredArgsConstructor 将自动生成一个构造函数,注入final标识的bean
多个构造函数时 需要加 onConstructor = @__(@Autowired) ,那么编译后的代码为在生成的构造函数上加@Autowired,标识使用这个构造函数初始化, 不然spring 不知道使用哪个构造函数初始化