我已将spring boot应用程序迁移到2.0,并发现了hikari连接池的一些问题.当我获取数据库数据时,这导致hikari cp超时ie.连接不可用.我不知道为什么在以前的版本中这个工作正常.
因此我尝试使用此配置的tomcat池,application.yml但它不起作用(正确的YAML格式).
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
Run Code Online (Sandbox Code Playgroud)
我的pom.xml有这些与DB事物相关的依赖:
spring-boot-jpa
spring-boot-jdbc
jdbc7
Run Code Online (Sandbox Code Playgroud)
如何排除hikari并使用tomcat连接池?
我已经实现了自己的类来表示基于 UserType 类的数据库矢量数据。
我的例子:
class MyVectorType implements UserType {
@Override
public int[] sqlTypes() {
return new int[] { Types.ARRAY };
}
};
@Entity
@Table("MY_ENTITY")
public class MyEntity {
private MyVectorType myVectorType;
}
Run Code Online (Sandbox Code Playgroud)
但是,此类不能用于使用 h2 方言进行测试,即。在内存数据库中。有错误:没有 JDBC 类型的方言映射:2003。
因此,我想从测试中排除此实体(包括存储库),但这不起作用:
@SpringBootApplication
@ComponentScan(excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
MyEntity.class, MyEntityRepository.class})
})
public class ApiApplication {
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
有什么问题或者有什么解决这个问题的最佳实践?
编辑 1:固定示例 - 添加了正确的实体和存储库
解决方案 1: 我认为目前唯一可能的解决方案是将实体类(需要排除)移动到其他包。然后设置@EntityScan 只扫描未排除的包。ComponentScan 中的排除过滤器似乎只适用于 @Component 类,而不适用于 @Entity。然而,这并不是解决这个问题的绝对最佳实践。
spring-boot ×2
connection ×1
default ×1
dialect ×1
h2 ×1
pool ×1
spring ×1
tomcat ×1
usertype ×1