Not throwing SSL Exception when enabling useSSL=true - mysql

I want to enable SSL connections while connecting to MySQL. Ideally my application should through exception because I have still not configured certificates while starting the application. But it is getting successfully restarted and able to connect to DB. I am using MySQL version 8 and spring boot 2.6.
spring.datasource.url=jdbc:mysql://localhost:3306/sms?verifyServerCertificate=true&useSSL=true&requireSSL=true
#spring.datasource.username=root
#spring.datasource.password=root
2022-07-28 16:26:40.659 INFO 15036 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-07-28 16:26:40.926 WARN 15036 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-07-28 16:26:41.656 INFO 15036 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9076 (https) with context path ''
2022-07-28 16:26:41.759 INFO 15036 --- [ main] n.j.s.StudentManagementSystemApplication : Started StudentManagementSystemApplication in 5.878 seconds (JVM running for 6.351)

Related

Gitlab CI ParameterResolutionException Failed to resolve parameter

I have test case that works fine in my local eclipse environment.
#Test
#Order(1)
void testTitle(#Arguments("--headless") ChromeDriver driver) {
driver.get("https://google.com");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
assertThat(driver.getTitle(), containsString("Google"));
}
But when I used the same in Gitlab it fails. I used the following docker image: maven:3.3.9-jdk-8.
It downloads and extracts chrome driver
https://chromedriver.storage.googleapis.com/90.0.4430.24/chromedriver_linux64.zip
2021-05-17 16:33:54.508 INFO --- [ main] i.g.bonigarcia.wdm.online.Downloader : Downloading https://chromedriver.storage.googleapis.com/90.0.4430.24/chromedriver_linux64.zip
2021-05-17 16:33:54.977 INFO --- [ main] i.g.bonigarcia.wdm.online.Downloader : Extracting driver from compressed file chromedriver_linux64.zip
2021-05-17 16:33:55.083 INFO --- [ main] i.g.bonigarcia.wdm.WebDriverManager : Exporting webdriver.chrome.driver as /root/.cache/selenium/chromedriver/linux64/90.0.4430.24/chromedriver
but shows the following error during test execution
Caused by: io.github.bonigarcia.seljup.SeleniumJupiterException:
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
Any idea from anyone?
I found the issue and resolved it. Needed to use another docker image maven-chrome.

Accessing data MySQL. Freezing on build

I am currently following along with this document:
https://spring.io/guides/gs/accessing-data-mysql/
and when I build using Gradle, the process does not finish executing.
20-10-11 18:12:09.099 INFO 4584 --- [task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-10-11 18:12:09.245 INFO 4584 --- [main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-10-11 18:12:09.253 INFO 4584 --- [main] c.e.a.AccessingDataMysqlApplication : Started AccessingDataMysqlApplication in 4.295 seconds (JVM running for 4.699)
<=========----> 75% EXECUTING [4m 32s]
I am new to Spring and starting a project from the ground up and do not know where to begin looking to solve this issue.
You are not just building the application - you are actually running it. And since it is a web application, listening to web requests on localhost:8080/demo, it runs until you exit it with ctrl+c.

spring boot and RDS db. Failed Conexion

i not conection.
have db in RDS amazon and have app in spring boot with hibernate...
state db is public..
i have conexion in local with workwench mysql. but not with app..
HELP ME PLEASE!!
Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2020-06-30 13:21:16.187 INFO 22852 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-06-30 13:21:16.195 INFO 22852 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-06-30 13:21:16.198 WARN 22852 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2020-06-30 13:21:17.960 ERROR 22852 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
java.sql.SQLException: Access denied for user 'master'#'186.23.179.139' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.20.jar:8.0.20]
enter image description here
spring.datasource.url=jdbc:mysql://autofabricadb.clbpfrarz8ji.sa-east-1.rds.amazonaws.com:3306/dbautofabrica
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
I HAVE CONEXIONNN BUT NOW SHOWW THE NEXT
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132) [mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) [mysql-connector-java-8.0.20.jar:8.0.20]
Have you inserted dependency(maven or gradle whatever you used to build the application) of mysql connector/jdbc driver for mysql, Make sure you've compatible version of jdbc mysql connector and your mysql version. Also keep in mind if your master user password and credentials maintained in your application properties file along with datasource url.

HikariCP connection pools hangs in spring-batch 4.0

We have updated our Spring Batch based application to the newest version of Spring Batch 4.x and Boot 2.0.x and having some problems with the HikariCP MySQL connection pool.
If I use the default maxPoolSize of 10 connections and I'm using 5 threads which each starts a simple dummy job this works ok. (Using SimpleJobLauncher). All Jobs are started immediately and after that the HikariCP pool has all used connections returned.
The problem starts when I do the same but then with 11 threads. Then I see that the application hangs until a connection timeout, and then the jobs are started. I expected that the first 10 jobs will start and after the first one finished the 11th job...
Before the jobs start I see this:
HikariPool-1 - Pool stats (total=10, active=0, idle=10, waiting=0)
Now I start 11 jobs and the application will hang for 30 seconds...
2019-01-21 11:25:01.256 INFO 10194 --- [ver (CliServer)] c.n.r.i.batch.cli.CliClientHandler : Start 11 jobs
2019-01-21 11:25:30.928 DEBUG 10194 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Pool stats (total=10, active=10, idle=0, waiting=2)
2019-01-21 11:25:35.990 DEBUG 10194 --- [ Thread-10] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Timeout failure stats (total=10, active=10, idle=0, waiting=1)
2019-01-21 11:25:35.992 DEBUG 10194 --- [ Thread-6] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Timeout failure stats (total=10, active=10, idle=0, waiting=1)
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:305)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean$1.invoke(AbstractJobRepositoryFactoryBean.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy74.createJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:131)
at com.xx.yy.zz.batch.cli.commands.DummyCliCommand$1.run(DummyCliCommand.java:54)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:697)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:196)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:161)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:262)
... 12 more
And after this timeout the first jobs are started...
2019-01-21 11:25:36.061 INFO 10194 --- [ Thread-11] c.n.r.i.b.u.c.BlockingThreadPoolExecutor : [sftp-executor] 3 running jobs, 0 queued jobs, 2000 jobs allowed
2019-01-21 11:25:36.062 INFO 10194 --- [ Thread-5] c.n.r.i.b.u.c.BlockingThreadPoolExecutor : [sftp-executor] 3 running jobs, 0 queued jobs, 2000 jobs allowed
2019-01-21 11:25:36.061 INFO 10194 --- [ Thread-3] c.n.r.i.b.u.c.BlockingThreadPoolExecutor : [sftp-executor] 3 running jobs, 0 queued jobs, 2000 jobs allowed
2019-01-21 11:25:36.063 INFO 10194 --- [pool-1-thread-2] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=dummyJob]] launched with the following parameters: [{dummy=f5c864d9-8a74-4d51-9a53-e3fc5c0b731d}]
Version:
- HikariCP 2.7.9
- spring-batch-core 4.0.1
- Hibernate Core 5.2.17.Final
- spring-boot 2.0.5
I don't understand why the pool hangs? (The Dummy Jobs do only sleep a second)
HikariCP config
allowPoolSuspension.............false
autoCommit......................true
catalog.........................none
connectionInitSql...............none
connectionTestQuery.............none
connectionTimeout...............30000
dataSource......................none
dataSourceClassName.............none
dataSourceJNDI..................none
dataSourceProperties............{usePipelineAuth=false, password=<masked>, prepStmtCacheSqlLimit=2048, rewriteBatchedStatements=false, useSSL=false, cachePrepStmts=true, useServerPrepStmts=true, prepStmtCacheSize=250}
driverClassName................."com.mysql.jdbc.Driver"
healthCheckProperties...........{}
healthCheckRegistry.............none
idleTimeout.....................600000
initializationFailTimeout.......1
isolateInternalQueries..........false
jdbcUrl.........................jdbc:mysql://localhost:3306/development
leakDetectionThreshold..........60000
maxLifetime.....................1800000
maximumPoolSize.................10
metricRegistry..................none
metricsTrackerFactory...........none
minimumIdle.....................10
password........................<masked>
poolName........................"HikariPool-1"
readOnly........................false
registerMbeans..................true
scheduledExecutor...............none
schema..........................none
threadFactory...................internal
transactionIsolation............default
username........................"user"
validationTimeout...............5000
The thread limit needs to be less than the maximum pool size of the datasource that spring batch is using with its jobrepository. So for your case, since your datasource pool size is 10, you should use no more than 9 threads.
In the case of an asynchronous taskExecutor(TaskExecutor) the number of concurrent tasklet executions can be throttled (beyond any throttling provided by a thread pool). The throttle limit should be less than the data source pool size used in the job repository for this step.
org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder#throttleLimit

Flyway Unable to obtain Jdbc connection with MySQL

Hello everybody I am trying to connect my Spring boot App with Mysql but unfortunately it does not work.
application.properties file:
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=*********
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.tomcat.max-active=1
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
The errors that I am getting are the following:
2018-07-06 18:32:10.832 WARN 7180 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : maxIdle is larger than maxActive, setting maxIdle to: 1
Fri Jul 06 18:32:10 CEST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
2018-07-06 18:32:11.093 ERROR 7180 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: Unknown system variable 'query_cache_size'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.41.jar:5.1.41]
at com.auth0.samples.bootfaces.Application.main(Application.java:21) [classes/:na]
2018-07-06 18:32:11.109 WARN 7180 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-07-06 18:32:11.176 ERROR 7180 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
Caused by: org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56) ~[flyway-core-3.2.1.jar:na]
pport.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 18 common frames omitted
Caused by: java.sql.SQLException: Unknown system variable 'query_cache_size'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.41.jar:5.1.41]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) ~[mysql-connector-java-5.1.41.jar:5.1.41]