Spring Boot App using MYSQL not starting - url attribute is not specified - spring-boot

I was following some tutorials and docs on how to connect Spring Boot apps with MySQL database but it gives me a start up error all the time even tho I have the url specified in the app.properties file.
spring.datasource.url=jdbc:mysql://localhost:3306/cryptodb01
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
spring.jackson.serialization.indent-output=true
I am getting this error everytime I try to run the app:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
My dependencies are these

Related

Why doesn't h2-console default db name match the db name defined in application.properties file?

I am new to spring boot and taking a beginner course on udemy developing a project.
Below is my application.properties file -
application.properties
#logging
logging.level.com.vega.springit=DEBUG
info.application.name=Springit
info.application.description=Reddit clone using spring boot 2
info.application.version=0.0.1
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
#h2
spring.h2.console.enabled=true
#datasource (default to testdb)
spring.datasource.name=springit
The default database on the h2-console is still testdb
And this is what I see on the console -
2020-11-29 01:19:29.315 INFO 28396 --- [ restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:358023a0-911e-4064-b2ec-e7046556c517'
My questions are -
Why doesn't h2-console display the database name that is set in the app.properties file?
Why does the console say database available at 'jdbc:hs:mem:xxx'?
When I try to connect to testdb or springit (as set in the file), I get following error -
Database "C:/Users/zankh/test" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help)
Also tried, connecting to 'jdbc:h2:mem:springit', but still get the same error.
I can connect to 'jdbc:hs:mem:xxx' but that's not how it works for the instructor in the course. What am I doing wrong here?
TIA
I fixed the problem by adding spring.datasource.url to the app.properties file
application.properties
#logging
logging.level.com.vega.springit=DEBUG
info.application.name=Springit
info.application.description=Reddit clone using spring boot 2
info.application.version=0.0.1
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
#h2
spring.h2.console.enabled=true
#datasource (default to testdb)
spring.datasource.name=springit
spring.datasource.url=jdbc:h2:mem:springit

TestContainer Oracle

according to https://www.testcontainers.org/modules/databases/jdbc/#database-containers-launched-via-jdbc-url-scheme , i'm trying to create an Oracle Container with Quarkus using jdbc url scheme.
After provided a valid docker image ("store/oracle/database-instantclient:12.2.0.1") and set this properties:
"%test":
quarkus:
datasource:
jdbc:
driver: org.testcontainers.jdbc.ContainerDatabaseDriver
url: jdbc:tc:oracle:///databasename
db-kind: other
i get this error:
Container is started (JDBC URL: jdbc:oracle:thin:system/oracle#localhost:32827:xe)
2020-11-09 17:33:06,719 INFO [🐳 .2.0.1]] (Agroal_13889837441) Container store/oracle/database-instantclient:12.2.0.1 started in PT4M7.8483772S
2020-11-09 17:33:06,738 WARN [io.agr.pool] (Agroal_13889837441) Datasource '<default>': Could not create new connection
2020-11-09 17:33:06,805 ERROR [io.qua.application] (main) Failed to start application (with profile test): org.flywaydb.core.internal.exception.FlywaySqlException:
Unable to obtain connection from database: Could not create new connection
--------------------------------------------------------------------------
SQL State : null
Error Code : 0
Message : Could not create new connection
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:65)
at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:80)
at org.flywaydb.core.Flyway.execute(Flyway.java:453)
at org.flywaydb.core.Flyway.migrate(Flyway.java:158)
Can someone help me?
If I remember correctly, Flyway community editions (that ships with Quarkus) does not have support for Oracle. You need to use the Enterprise edition.
You need to replace the Quarkus Flyway dependency. Just exclude the one included and add the enterprise one (either in Maven or Gradle).

Spring :: Hikari Pool-1 starting... gets stuck on this line upon running the application

I have developed a spring boot application. previously it was working fine. now it is not working. it prints "HikariPool-1 - Starting..." and stucks here, does not move forward.
Below is my application.properties file for db configuration.
spring.datasource.url=jdbc:mariadb://localhost:3306/dbname
spring.datasource.username=username
spring.datasource.password=pwd
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
#spring.datasource.hikari.maxLifetime=0
#spring.datasource.hikari.leak-detection-threshold=10000
#
spring.datasource.continue-on-error=true
spring.jmx.default-domain=something
is there anything wrong in the above configuration which is causing this?
I tried with maxLifetime and leak-detection-threshold also but did not help so commented those in above configurations.

Spring Boot Actuator Liquibase endpoint fail

I'm trying to use Liquibase with Spring Boot.
Here is my application.properties file:
# ----------------------------------------
# DATA PROPERTIES
# ----------------------------------------
spring.datasource.url=jdbc:postgresql://xxxxxx:5432/dev
spring.datasource.schema=my_schema
spring.datasource.username=my_username
spring.datasource.password=my_password
# LIQUIBASE (LiquibaseProperties)
liquibase.default-schema=${spring.datasource.schema}
liquibase.user=${spring.datasource.username}
liquibase.password=${spring.datasource.password}
Change sets are well applied (table creation is ok).
The problem comes when I access /liquibase actuator's endpoint, I get a 500 error:
Unable to get Liquibase changelog
I also get the following log:
org.postgresql.util.PSQLException: ERROR: relation "public.databasechangelog" does not exist
If thing the problem is the schema prefix used to access changelog table: "public" versus "my_schema".
I thought spring.datasource.schema was the right parameter to set ?
Here is a working solution (come from this answer):
# ----------------------------------------
# DATA PROPERTIES
# ----------------------------------------
spring.datasource.url=jdbc:postgresql://xxxxxx:5432/dev?currentSchema=my_schema
Just a guess here - I think that the issue is that your 'real' schema is being set by the spring.datasource.schema but the liquibase tables are being stored in public and it may be that the Spring Boot actuator doesn't know that those can be separate.

Spring Boot JMS & Batch

Previously everything worked properly. Today I configured Spring Batch together with my Spring Boot application and faced an issue with application.properties.
I have following properties encrypted with Jasypt:
spring.profiles.active=https
ENVIRONMENT=h2
#aws sqs
aws.sqs.account.access.key=ENC(kjsdh456fgkjhdfsgkjhdfg)
#queue message listener
queue.message.listener.task.executor.threads.number=1
queue.message.listener.task.executor.max.concurrent.consumers=1
Now, in order to configure Spring Batch I added
ENVIRONMENT=h2
to application.properties file.
also, I have added batch-h2.properties file:
# Placeholders batch.* for H2 database:
batch.jdbc.driver=org.h2.Driver
batch.jdbc.url=jdbc:h2:~/testdb;CIPHER=AES;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
batch.jdbc.user=sa
batch.jdbc.password="sa sa"
batch.jdbc.testWhileIdle=false
batch.jdbc.validationQuery=
batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-h2.sql
batch.schema.script=classpath:/org/springframework/batch/core/schema-h2.sql
batch.business.schema.script=classpath:/business-schema-h2.sql
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.H2SequenceMaxValueIncrementer
batch.database.incrementer.parent=sequenceIncrementerParent
batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler
batch.grid.size=2
batch.jdbc.pool.size=6
batch.verify.cursor.position=true
batch.isolationlevel=ISOLATION_SERIALIZABLE
batch.table.prefix=BATCH_
and after that I continuously receiving following exception:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'aws.sqs.account.access.key' in string value "${aws.sqs.account.access.key}"
aws.sqs.account.access.key property now cannot be resolved.
I'm injecting this property into my configuration:
#Configuration
public class SQSConfig {
#Value("${aws.sqs.account.access.key}")
private String accessKey;
How to fix it ?

Resources