Flyway Unable to obtain Jdbc connection with MySQL - 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]

Related

Not throwing SSL Exception when enabling useSSL=true

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)

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.

HikariPool-2 - Failed to validate connection

I am new to spring boot so doesn't know much about configuration in application.properties or pom.xml . I'm trying to do a CRUD operation in MySQL DB hosted in Azure VM. Once I start my spring-boot application and perform a DB operation, it works fine the first time. After a while, say 4-5 mins, when another operation is performed, then the springboot application fails to connect to the DB and throws Exception.
PSB the log:
2019-12-23 14:43:00.063 DEBUG 64148 --- [http-nio-4400-exec-5] o.s.web.servlet.DispatcherServlet : GET "/rest/path/getFrequentDetail?queryParam1=value1&queryParam2=value2", parameters={masked}
2019-12-23 14:43:00.063 DEBUG 64148 --- [http-nio-4400-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.http.ResponseEntity<com.bla.bla> com.bla.bla(java.lang.String,java.lang.String) throws java.io.IOException
2019-12-23 14:43:00.064 DEBUG 64148 --- [http-nio-4400-exec-5] o.h.e.t.internal.TransactionImpl : On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2019-12-23 14:43:00.064 DEBUG 64148 --- [http-nio-4400-exec-5] o.h.e.t.internal.TransactionImpl : begin
2019-12-23 14:43:05.073 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl#503a164d (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:10.077 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl#56e33182 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:15.079 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl#43689c2d (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:20.082 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl#306934d0 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:25.085 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl#7754c08f (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:30.087 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl#3a33fdce (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:30.091 DEBUG 64148 --- [http-nio-4400-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper : Unable to acquire JDBC Connection [n/a]
java.sql.SQLTransientConnectionException: HikariPool-2 - Connection is not available, request timed out after 30024ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:697)
application.properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Hikari parameters
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
spring.datasource.initialize=true
spring.datasource.schema=classpath:schema.sql
spring.batch.initialize-schema=ALWAYS
spring.batch.job.enabled: false
I've searched through the internet for similar issues and mostly it was related to connection remaining open or MySQL timeout configuration.
Both of these seems fine in my case.
All operations are done using JPA.
Timeout in mysql is fairly high:
innodb_lock_wait_timeout 50
wait_timeout 28800
mysqlx_wait_timeout 28800
Please help.

Spring Boot: Jdbc javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify

I am currently learning more about implementing JDBC and using databases in a Spring Boot webapp, and I encountered the following Stack Trace written in the bottom of the post.
I have created a simple Employee model, and I am trying to execute some database code on the same class which my main() lies in. The model and the main class are the only two java files existing in this whole project. I am trying to implement the following run() code that overrides the one from the interface, CommandLineRunner, but I do not get the logs that should come after log.info("Part A:"):
log.info("Part A:")
employees.forEach(employee -> {log.info(employee.toString());
log.info("part a");});
--Things I noticed:
I noticed that the last line of the log before the stack trace starts comes from: "Thread-1" instead of "main". I think that means that a thread from somewhere other than the main encountered an error and closed connection before when it should close normally.
Also, I think that because HikariPool closed before "peer's close_notify", which I presume that it refers to the normal closure of HikariPool, I am not able to see the final bit of logging that I have kept trying to procure. The final bit of logging that I want to see is the logging of the employee that has become inserted into my database.
The final bit of logging that I want to see should be procured from this line of code:
employees.forEach(employee -> {log.info(employee.toString());
log.info("part a");});
--Things to note:
Because of this line in the log, I thought I would see the employee inserted into my database, but when I queried directly on MySQL Command Line Client, it returned an empty set:
2018-11-03 21:08:35.362 INFO 2408 --- [ main] c.j.jdbctest1.JdbcTest1Application : rows affected: 1
I don't understand why a row has been affected when nothing has been inserted into the database.
The stacktrace and logs: (The stacktrace pasted below actually repeats itself several more times but I cut it off for brevity.)
2018-11-03 21:08:32.997 INFO 2408 --- [ main] c.j.jdbctest1.JdbcTest1Application : Starting JdbcTest1Application on KitKat with PID 2408 (C:\Users\Nano\Downloads\jdbc-test1\jdbc-test1\target\classes started by Nano in C:\Users\Nano\Downloads\jdbc-test1\jdbc-test1)
2018-11-03 21:08:33.003 INFO 2408 --- [ main] c.j.jdbctest1.JdbcTest1Application : No active profile set, falling back to default profiles: default
2018-11-03 21:08:33.770 INFO 2408 --- [ main] c.j.jdbctest1.JdbcTest1Application : Started JdbcTest1Application in 1.024 seconds (JVM running for 1.778)
2018-11-03 21:08:33.770 INFO 2408 --- [ main] c.j.jdbctest1.JdbcTest1Application : Creating tables
2018-11-03 21:08:33.770 INFO 2408 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-11-03 21:08:34.082 INFO 2408 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-11-03 21:08:35.135 INFO 2408 --- [ main] c.j.jdbctest1.JdbcTest1Application : Inserting Baggins Hopkins
2018-11-03 21:08:35.362 INFO 2408 --- [ main] c.j.jdbctest1.JdbcTest1Application : rows affected: 1
2018-11-03 21:08:35.362 INFO 2408 --- [ main] c.j.jdbctest1.JdbcTest1Application : Querying for employee
2018-11-03 21:08:36.065 INFO 2408 --- [ main] c.j.jdbctest1.JdbcTest1Application : Part A:
2018-11-03 21:08:36.065 INFO 2408 --- [ Thread-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
Sat Nov 03 21:08:36 KST 2018 WARN: Caught while disconnecting...
EXCEPTION STACK TRACE:
** BEGIN NESTED EXCEPTION **
javax.net.ssl.SSLException
MESSAGE: closing inbound before receiving peer's close_notify
STACKTRACE:
javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:129)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:645)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:624)
at com.mysql.cj.protocol.a.NativeProtocol.quit(NativeProtocol.java:1312)
at com.mysql.cj.NativeSession.quit(NativeSession.java:182)
at com.mysql.cj.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:1750)
at com.mysql.cj.jdbc.ConnectionImpl.close(ConnectionImpl.java:720)
at com.zaxxer.hikari.pool.PoolBase.quietlyCloseConnection(PoolBase.java:135)
at com.zaxxer.hikari.pool.HikariPool.lambda$closeConnection$1(HikariPool.java:441)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
** END NESTED EXCEPTION **
The Java Code:
#SpringBootApplication
public class JdbcTest1Application implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(JdbcTest1Application.class);
#Autowired
JdbcTemplate jdbcTemplate;
public static void main(String[] args) {
SpringApplication.run(JdbcTest1Application.class, args);
}
#Override
public void run(String... args) throws Exception {
log.info("Creating tables");
jdbcTemplate.execute("DROP TABLE IF EXISTS employees");
jdbcTemplate.execute("CREATE TABLE employees (emp_id int, name varchar(100), role varchar(100), status varchar(100))");
log.info("Inserting Baggins Hopkins");
int rowsAffected = jdbcTemplate.update("INSERT INTO EMPLOYEE(EMP_ID, NAME, ROLE, STATUS)"
+ " VALUES(1,'Baggins Hopkins','thief','WORKING')");
log.info("rows affected: "+ Integer.toString(rowsAffected));
log.info("Querying for employee");
String sql = "SELECT emp_id,name,role,status FROM employees";
List<Employee> employees = jdbcTemplate.query(sql,(rs, rowNum)->
new Employee(rs.getInt("emp_id"), rs.getString("name"),
rs.getString("role"),Status.valueOf(rs.getString("status"))));
log.info("Part A:");
employees.forEach(employee -> {log.info(employee.toString());
log.info("part a");});
}
}
Also just in case this matters, I pasted this code from application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/employee_database
spring.datasource.username=employee
spring.datasource.password=employee
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
The SSL connection to the database is failing, try changing your datasource URL to:
spring.datasource.url=jdbc:mysql://localhost:3306/employee_database?useSSL=false
The warning looks like a MySQL driver bug with Java 11 and SSL enabled : https://bugs.mysql.com/bug.php?id=93590
Deactivating encryption because of a driver warning is a bad idea.
Your insertion problem looks more like a classic transaction issue though, I doubt it is related to the SSL warning.
This Worked for me
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.20</version>
</dependency>
I also faced the same issue.
if you look the the stacktrace, it's cleary mentioned what to do -
Sat Mar 16 09:00:01 IST 2019 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.
so after disabling the ssl by making changes in data source url solved the problem -
spring.datasource.url=jdbc:mysql://localhost:3306/security?useSSL=false
To solve this problem, it took me about three days.
(Edit: This is a workaround for testing and not actually a solution.)
At first, I started solving the problem from trying to configure my own SSL for mysql, and I spent quite a few hours on that. Too much time had passed until I realized configuring it had to do with Cmake and C++, which made me give up. It was very frustrating. However I did not give up and tried to disable SSL entirely through a method that hasn't been found. And I eventually did find the method. Here it is:
You have to use the legacy password for MySQL. The legacy password is the way MySQL authenticated things in version 5.7x.
Open up the MySQL installer again, and reconfigure the MySQL Server settings.
When you get there you will see this screen:
The screen that you should get to
You might get some errors when reaching the final stage of the reconfiguration:
I had problems at the final stage I had no idea how to fix so I uninstalled MySQL altogether. I use windows. I deleted the MySQL project root directory from Program Files to uninstall MySQL. I also deleted the databases saved in Program Data (a hidden folder in the C Drive) because I wanted to start afresh(WARNING: this will delete all your previously saved data!). Uninstalling MySQL from the control panel might not be enough to completely erase MySQL from your computer.
Delete all *.pem files in C:\ProgramData\MySQL\MySQL Server 8.0\Data. (or move it somewhere else, which is what I did)
You might not see ProgramData in the C Drive. That is because it is a hidden folder. In order to see hidden folders:
search for folder options in the control panel.
Go to view.
Under 'Advanced settings' and under 'Hidden files and folders' of that, click "Show hidden files, folders, and drives."
Go to C:\ProgramData\MySQL\MySQL Server 8.0 and open my.cnf (or my.ini). Add the following line after [mysqld]:
ssl=0
Then save. It should work now.
References:
https://community.atlassian.com/t5/Confluence-questions/MySQL-Public-Key-Retrieval-is-not-allowed/qaq-p/778956
https://scalegrid.io/blog/configuring-and-managing-ssl-on-your-mysql-server/
My similar problem in a tomcat trying to conect via ssl to Aurora mysql (AWS)
I solved the problem by updating the driver version from 'mysql-connector-java-5.1.40.jar' to 'mysql-connector-java-5.1.49.jar', and installing a root CA into ceacerts:
keytool -import -trustcacerts -file rds-ca-2019-root.pem -keystore /<your_java_home>/lib/security/cacerts
Hope be use to you
Try using the following URL. As they suggested use useSSL=false Also, Make sure to use <&amp> instead of just & when you have multiple properties defined in your URL.
jdbc:mysql://localhost:3306/TestDB?serverTimezone=PST&useSSL=false
I was also facing the same issue
But then i updated the mysql-connector-java version from 5.1.46 to 8.0.20 and by changing com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver
it solved my issue
My similary prolem is in spark,
I solove the problem by down the java verion from
'openjdk version "1.8.0_275"' to 'openjdk version "1.8.0_265"',
hope be use to you
I had this issue and decided to use Carrier Pigeon Protocol's solution until I accidentally solved it by updating Tomcat from version 9.0.12 to 9.0.16.
I faced a similar issue when I upgraded the Java version in my server to 11 from 8.
The spring boot started supporting Java 11 from 2.1 and onwards. So make sure your project's dependencies are also updated accordingly. This is relevant for this answer as SpringBoot also influence MySQL connector, Hibernate core, and other dependencies.
The inability to connect to DB was resulting in some more NoClassDefFoundErrors. So make sure you solve this first before looking into other errors.
An example pom dependency for the SpringBoot starter
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.12.RELEASE</version>
<relativePath />
</parent>
Hope this helps someone.
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: name-unit] Unable to build Hibernate SessionFactory
I had exactly the same problem, I also modified a false my useSSL like this useSSL=false and it works fine.
I think for those who use intelliJ ultimate the error the problem does not arise. But for those who use the community version "yes" also for those who are on netbeans like my case. This concerns the management of persistence.xml files and the EntityManagerHolder file
Rather than disabling SSL/TLS I appended the following to the database connection string: &enabledTLSProtocols=TLSv1.2

Cannot connect mysql to Grails 3 application

I am using grails version 3.1.4 and I am trying to connect my application to mysql database.
I had followed the link at How to connect Grails 3.0 to my local Mysql database to connect mysql database to my Grails 3 application but I am getting the following error:
ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistenceInterceptor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.grails.orm.hibernate4.support.AggregatePersistenceContextInterceptor.setHibernateDatastores(org.grails.orm.hibernate.AbstractHibernateDatastore[]); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.grails.orm.hibernate.AbstractHibernateDatastore] found for dependency [array of org.grails.orm.hibernate.AbstractHibernateDatastore]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at grails.boot.GrailsApp.run(GrailsApp.groovy:55)
at grails.boot.GrailsApp.run(GrailsApp.groovy:365)
at grails.boot.GrailsApp.run(GrailsApp.groovy:354)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at helloworld.Application.main(Application.groovy:8)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.grails.orm.hibernate4.support.AggregatePersistenceContextInterceptor.setHibernateDatastores(org.grails.orm.hibernate.AbstractHibernateDatastore[]); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.grails.orm.hibernate.AbstractHibernateDatastore] found for dependency [array of org.grails.orm.hibernate.AbstractHibernateDatastore]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:661)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 22 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.grails.orm.hibernate.AbstractHibernateDatastore] found for dependency [array of org.grails.orm.hibernate.AbstractHibernateDatastore]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:618)
... 24 common frames omitted
Java HotSpot(TM) Client VM warning: TieredCompilation is disabled in this release.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command 'C:\Program Files (x86)\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error |
Failed to start server (Use --stacktrace to see the full trace)
Java HotSpot(TM) Client VM warning: TieredCompilation is disabled in this release.
Process finished with exit code 1
Here's my application.yml
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: root
password: root123
environments:
development:
dataSource:
dbCreate: update
url : jdbc:mysql://localhost:3306/collegedb?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true
I have also added runtime 'mysql:mysql-connector-java:5.1.36' to build.gradle file.
I have created the database named collegedb at mysql. Can't figure out what is the problem. Any help/suggestions are appreciated. Cheers.
You have misstyped config in application.yml:
environments:
development:
dataSource:
dbCreate: update
url : jdbc:mysql://localhost:3306/collegedb?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true
It should be:
environments:
development:
dataSource:
dbCreate: update
url : jdbc:mysql://localhost:3306/collegedb?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true