Как настройка объединения подключения Spring JDBC с помощью Spring Boot?JAVA

Программисты JAVA общаются здесь
Anonymous
Как настройка объединения подключения Spring JDBC с помощью Spring Boot?

Сообщение Anonymous »

Я использую Spring Boot 1.5.4 с Spring jdbc. < /p>

Имеет пружинный загрузочный микросервис, который использует Spring JDBC, имеет следующую проблему при попытке провести HTTP -точку ( После того, как куча пользователей попытается провести HTTP -точку), которая протекает к этой весной JDBC Call: < /p>

2018-10-10 19:40:02 [http-nio-8081-exec-4] ERROR c.v.r.RepositoryImpl - Problem in updateData() method:
"org.springframework.dao.DataAccessResourceFailureException: PreparedStatementCallback; SQL [select a.user_id,b.user_id, from user a join user_profile b where a.user_id=b.user_id and a.date=?;]; No operations allowed after connection closed.; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:79)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 28,915,589 milliseconds ago. The last packet sent successfully to the server was 9 milliseconds ago.
at com.myapp.repository.RepositoryImpl.updateData(RepositoryImpl.java:74)
at com.myapp.repository.RepositoryImpl$$FastClassBySpringCGLIB$$1be9dd8e.invoke()
... 52 common frames omitted
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2914)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3337)
... 83 common frames omitted
< /code>

pom.xml:

MyService
jar
1.0


org.springframework.boot
spring-boot-starter-parent
1.5.4.RELEASE



1.7





org.springframework.boot
spring-boot-starter-web



org.springframework.boot
spring-boot-starter-jdbc



mysql
mysql-connector-java
5.1.33


< /code>

Я предполагаю, что мне нужно настроить пул соединений JDBC ... < /p>

Внутри моего приложения. , (У меня есть две разные базы данных - одна локальная и одна удаленная, его проигрышное соединение с удаленной базой данных; Database2): < /p>

# Local
spring.datasource.database1.url=jdbc:mysql://localhost/database1?zeroDateTimeBehavior=convertToNull
spring.datasource.database1.username=root
spring.datasource.database1.password=ret2my
spring.datasource.database1.driverClassName=com.mysql.jdbc.Driver

# Remote
spring.datasource.database2.url=jdbc:mysql://read-replica-database-production.cranmichpmc.us-west-2.rds.amazonaws.com/database2?zeroDateTimeBehavior=convertToNull
spring.datasource.database2.username=root
spring.datasource.database2.password=ret2a$$
spring.datasource.database2.driverClassName=com.mysql.jdbc.Driver
< /code>

Должен ли я добавить это для второй базы данных: < /p>

spring.datasource.database2.hikari.maximum-pool-size=10
spring.datasource.database2.hikari.connection-timeout=60000
< /code>

Есть ли другие полезные параметры, которые я должен рассмотреть? < /p>

Подробнее здесь: https://stackoverflow.com/questions/527 ... pring-boot

Вернуться в «JAVA»