【发布时间】:2019-10-20 03:19:37
【问题描述】:
我正在我的学校项目中使用微服务架构(使用 maven 和 spring boot JPA)制作应用程序 我正在使用的硬件: aws RDS(最大数据库连接为 66,这导致了我的问题) aws ec2-instance 免费层 我有 3 个微服务:员工、薪水和休假。 但是,只运行了 3 个微服务,我的数据库连接数达到了 40+。 我不知道如何限制服务可以创建的数据库连接数。
经过一番研究,我遇到了“连接池”这个词,所以我尝试设置tomcat连接池。
这是配置(我都做了)但它不起作用 我是否可以说如果配置正确,我的应用程序最多只能建立 5 个活动连接?
spring.datasource.tomcat.initial-size=5
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=5
spring.datasource.tomcat.max-idle=5
spring.datasource.tomcat.min-idle=1
spring.datasource.tomcat.default-auto-commit=true
这是查询代码
public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
@Query(
value = "select * from itsa.Employee;",
nativeQuery = true)
List<Employee> findAllEmployee();
@Query(
value = "SELECT * FROM Employee where id = :id",
nativeQuery = true)
List<Employee> findEmp(@Param("id") int id);
【问题讨论】:
标签: spring-boot tomcat database-connection microservices connection-pooling