Spring Boot can not connect to Mysql - java

have un problem connection data base with spring boot
I'm the sequel of a developer that is already working. I've been provided the sources but I can't launch the Spring Boot Java project with IntelliJ. I use a sever Xampp for my dataBase. But I have the following error
:: Spring Boot :: (v2.3.3.RELEASE)
2020-12-15 16:39:28.411 INFO 2384 --- [ main] c.a.myapp.myappApplication : Starting myappApplication on DESKTOP-DRP2JSE with PID 2384 (C:\Users\Admin\Downloads\myapp 2.0 Final\myappBack 2.0 - Final\myappBack\out\production\myappBack started by Admin in C:\Users\Admin\Downloads\myapp 2.0 Final\myappBack 2.0 - Final\myappBack)
2020-12-15 16:39:28.415 INFO 2384 --- [ main] c.a.myapp.myappApplication : No active profile set, falling back to default profiles: default
2020-12-15 16:39:29.382 INFO 2384 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-12-15 16:39:29.496 INFO 2384 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 108ms. Found 8 JPA repository interfaces.
2020-12-15 16:39:30.032 INFO 2384 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-12-15 16:39:30.040 INFO 2384 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-12-15 16:39:30.040 INFO 2384 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-12-15 16:39:30.396 INFO 2384 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-12-15 16:39:30.396 INFO 2384 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1922 ms
2020-12-15 16:39:30.498 WARN 2384 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-12-15 16:39:30.500 INFO 2384 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-12-15 16:39:30.513 INFO 2384 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-12-15 16:39:30.519 ERROR 2384 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
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
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
server.port=8081
server.servlet.session.timeout=1200
# JDBC URL of the database.
spring.datasource.url=jdbc:mysql://localhost:3306/myapp?zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=UTC
# Login username of the database.
spring.datasource.username= root
# Login password of the database.
spring.datasource.password=
# Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Whether to enable logging of SQL statements.
spring.jpa.show-sql=true
# DDL mode. This is actually a shortcut for the "hibernate.hbm2ddl.auto" property. Defaults to "create-drop" when using an embedded database and no schema manager was detected. Otherwise, defaults to "none".
spring.jpa.hibernate.ddl-auto=update
# Additional native properties to set on the JPA provider.
spring.jpa.database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.properties.hibernate.storage.storage_engine=innodb
# Avoid to restart server (only during dev phase) if DevTools are uninstall
# spring.thymeleaf.cache=false
# spring.security.user.name="root"
# spring.security.user.password="123"
spring.resources.add-mappings=true

The problem is written Reason: Failed to determine a suitable driver class. Classloader can not find driver-class-name in you classpath. Maybe missing MySQL library definition in the maven / gradle configuration.
Maven:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
Gradle:
runtimeOnly 'mysql:mysql-connector-java'
If MySQL library is existed, try to change driver-class-name definition as below.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
... instead of
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

it works, just force to reload the maven dependency and is ok;
just warning to fix
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Admin/Downloads/myapp%202.0%20Final/myappBack%202.0%20-%20Final/myappBack/target/myappService/WEB-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Admin/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

Check your mysql-connector-java version jar
if it's 5 it should be
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
if its 8 it should be
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Also I don't think you should have spaces after equal sign where is your username and password

Try and remove the spring.datasource.class-name property from the config file.
The url should be good enough to tell which classname is to be used.
Also set "logging.level.root=debug" in the properties to get some more details. See if that helps.

Related

Jasypt: Failed to bind properties under 'spring.datasource.password' to java.lang.String

I am using Jasypt in my Spring Boot app and encrypted passwords in app properties and docker-compose using proper annotation:
application.properties.yml:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/employee_db
username: postgres
password: ENC(fpEVpMwMbl4hbcoCKuhrpi...)
# jasypt
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
docker-compose.yml:
services:
db:
image: postgres:14.6-alpine
environment:
POSTGRES_DB: employee_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ENC(fpEVpMwMbl4hbcoCKuhrpi...)
After creating Docker image for database (db container), I add the VM options to IntelliJ and start the app. But I got the following error and cannot find a solution for that:
Description: Failed to bind properties under 'spring.datasource.password' to java.lang.String:
Reason: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.password' to java.lang.String
Action: Update your application's configuration
Any idea to solve the problem?
Here is the full log:
C:\Users\simpson\.jdks\corretto-17.0.5\bin\java.exe -Djasypt.encryptor.password=abnamro -XX:TieredStopAtLevel=1 -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2022.2.1\lib\idea_rt.jar=53749:
C:\Program Files\JetBrains\IntelliJ IDEA 2022.2.1\bin" -Dfile.encoding=UTF-8 -classpath "D:\employee-api\target\classes;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-starter-data-jpa\2.7.5\spring-boot-starter-data-jpa-2.7.5.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.7.5\spring-boot-starter-aop-2.7.5.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-aop\5.3.23\spring-aop-5.3.23.jar;C:\Users\simpson\.m2\repository\org\aspectj\aspectjweaver\1.9.7\aspectjweaver-1.9.7.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.7.5\spring-boot-starter-jdbc-2.7.5.jar;C:\Users\simpson\.m2\repository\com\zaxxer\HikariCP\4.0.3\HikariCP-4.0.3.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-jdbc\5.3.23\spring-jdbc-5.3.23.jar;C:\Users\simpson\.m2\repository\jakarta\transaction\jakarta.transaction-api\1.3.3\jakarta.transaction-api-1.3.3.jar;C:\Users\simpson\.m2\repository\jakarta\persistence\jakarta.persistence-api\2.2.3\jakarta.persistence-api-2.2.3.jar;C:\Users\simpson\.m2\repository\org\hibernate\hibernate-core\5.6.12.Final\hibernate-core-5.6.12.Final.jar;C:\Users\simpson\.m2\repository\org\jboss\logging\jboss-logging\3.4.3.Final\jboss-logging-3.4.3.Final.jar;C:\Users\simpson\.m2\repository\net\bytebuddy\byte-buddy\1.12.18\byte-buddy-1.12.18.jar;C:\Users\simpson\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\simpson\.m2\repository\org\jboss\jandex\2.4.2.Final\jandex-2.4.2.Final.jar;C:\Users\simpson\.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.1.2.Final\hibernate-commons-annotations-5.1.2.Final.jar;C:\Users\simpson\.m2\repository\org\glassfish\jaxb\jaxb-runtime\2.3.7\jaxb-runtime-2.3.7.jar;C:\Users\simpson\.m2\repository\org\glassfish\jaxb\txw2\2.3.7\txw2-2.3.7.jar;C:\Users\simpson\.m2\repository\com\sun\istack\istack-commons-runtime\3.0.12\istack-commons-runtime-3.0.12.jar;C:\Users\simpson\.m2\repository\com\sun\activation\jakarta.activation\1.2.2\jakarta.activation-1.2.2.jar;C:\Users\simpson\.m2\repository\org\springframework\data\spring-data-jpa\2.7.5\spring-data-jpa-2.7.5.jar;C:\Users\simpson\.m2\repository\org\springframework\data\spring-data-commons\2.7.5\spring-data-commons-2.7.5.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-orm\5.3.23\spring-orm-5.3.23.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-context\5.3.23\spring-context-5.3.23.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-tx\5.3.23\spring-tx-5.3.23.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-beans\5.3.23\spring-beans-5.3.23.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-aspects\5.3.23\spring-aspects-5.3.23.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.7.5\spring-boot-starter-web-2.7.5.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-starter\2.7.5\spring-boot-starter-2.7.5.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.7.5\spring-boot-starter-logging-2.7.5.jar;C:\Users\simpson\.m2\repository\ch\qos\logback\logback-classic\1.2.11\logback-classic-1.2.11.jar;C:\Users\simpsson\.m2\repository\ch\qos\logback\logback-core\1.2.11\logback-core-1.2.11.jar;C:\Users\simpson\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.17.2\log4j-to-slf4j-2.17.2.jar;C:\Users\simpson\.m2\repository\org\apache\logging\log4j\log4j-api\2.17.2\log4j-api-2.17.2.jar;C:\Users\simpson\.m2\repository\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;C:\Users\simpson\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\simpson\.m2\repository\org\yaml\snakeyaml\1.30\snakeyaml-1.30.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.7.5\spring-boot-starter-json-2.7.5.jar;C:\Users\simpson\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.13.4.2\jackson-databind-2.13.4.2.jar;C:\Users\simpson\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.13.4\jackson-annotations-2.13.4.jar;C:\Users\simpson\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.4\jackson-datatype-jdk8-2.13.4.jar;C:\Users\simpson\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.4\jackson-datatype-jsr310-2.13.4.jar;C:\Users\simpson\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.4\jackson-module-parameter-names-2.13.4.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.7.5\spring-boot-starter-tomcat-2.7.5.jar;C:\Users\simpson\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.68\tomcat-embed-core-9.0.68.jar;C:\Users\simpson\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.68\tomcat-embed-websocket-9.0.68.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-web\5.3.23\spring-web-5.3.23.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-webmvc\5.3.23\spring-webmvc-5.3.23.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-expression\5.3.23\spring-expression-5.3.23.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-starter-validation\3.0.0\spring-boot-starter-validation-3.0.0.jar;C:\Users\simpson\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.68\tomcat-embed-el-9.0.68.jar;C:\Users\simpson\.m2\repository\org\hibernate\validator\hibernate-validator\6.2.5.Final\hibernate-validator-6.2.5.Final.jar;C:\Users\simpson\.m2\repository\jakarta\validation\jakarta.validation-api\2.0.2\jakarta.validation-api-2.0.2.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-devtools\2.7.5\spring-boot-devtools-2.7.5.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot\2.7.5\spring-boot-2.7.5.jar;C:\Users\simpson\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.7.5\spring-boot-autoconfigure-2.7.5.jar;C:\Users\simpson\.m2\repository\org\projectlombok\lombok\1.18.24\lombok-1.18.24.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-boot-starter\3.0.0\springfox-boot-starter-3.0.0.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-oas\3.0.0\springfox-oas-3.0.0.jar;C:\Users\simpson\.m2\repository\io\swagger\core\v3\swagger-annotations\2.1.2\swagger-annotations-2.1.2.jar;C:\Users\simpson\.m2\repository\io\swagger\core\v3\swagger-models\2.1.2\swagger-models-2.1.2.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-spi\3.0.0\springfox-spi-3.0.0.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-schema\3.0.0\springfox-schema-3.0.0.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-core\3.0.0\springfox-core-3.0.0.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-spring-web\3.0.0\springfox-spring-web-3.0.0.jar;C:\Users\simpson\.m2\repository\io\github\classgraph\classgraph\4.8.83\classgraph-4.8.83.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-spring-webmvc\3.0.0\springfox-spring-webmvc-3.0.0.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-spring-webflux\3.0.0\springfox-spring-webflux-3.0.0.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-swagger-common\3.0.0\springfox-swagger-common-3.0.0.jar;C:\Users\simpson\.m2\repository\org\mapstruct\mapstruct\1.3.1.Final\mapstruct-1.3.1.Final.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-data-rest\3.0.0\springfox-data-rest-3.0.0.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-bean-validators\3.0.0\springfox-bean-validators-3.0.0.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-swagger2\3.0.0\springfox-swagger2-3.0.0.jar;C:\Users\simpson\.m2\repository\io\swagger\swagger-annotations\1.5.20\swagger-annotations-1.5.20.jar;C:\Users\simpson\.m2\repository\io\swagger\swagger-models\1.5.20\swagger-models-1.5.20.jar;C:\Users\simpson\.m2\repository\io\springfox\springfox-swagger-ui\3.0.0\springfox-swagger-ui-3.0.0.jar;C:\Users\simpson\.m2\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;C:\Users\simpson\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\simpson\.m2\repository\org\springframework\plugin\spring-plugin-core\2.0.0.RELEASE\spring-plugin-core-2.0.0.RELEASE.jar;C:\Users\simpson\.m2\repository\org\springframework\plugin\spring-plugin-metadata\2.0.0.RELEASE\spring-plugin-metadata-2.0.0.RELEASE.jar;C:\Users\simpson\.m2\repository\org\apache\commons\commons-text\1.10.0\commons-text-1.10.0.jar;C:\Users\simpson\.m2\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\Users\simpson\.m2\repository\com\github\ulisesbocchio\jasypt-spring-boot-starter\3.0.3\jasypt-spring-boot-starter-3.0.3.jar;C:\Users\simpson\.m2\repository\com\github\ulisesbocchio\jasypt-spring-boot\3.0.3\jasypt-spring-boot-3.0.3.jar;C:\Users\simpson\.m2\repository\org\jasypt\jasypt\1.9.3\jasypt-1.9.3.jar;C:\Users\simpson\.m2\repository\org\flywaydb\flyway-core\9.8.3\flyway-core-9.8.3.jar;C:\Users\simpson\.m2\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-toml\2.13.4\jackson-dataformat-toml-2.13.4.jar;C:\Users\simpson\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.13.4\jackson-core-2.13.4.jar;C:\Users\simpson\.m2\repository\org\postgresql\postgresql\42.5.1\postgresql-42.5.1.jar;C:\Users\simpson\.m2\repository\org\checkerframework\checker-qual\3.5.0\checker-qual-3.5.0.jar;C:\Users\simpson\.m2\repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;C:\Users\simpson\.m2\repository\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-core\5.3.23\spring-core-5.3.23.jar;C:\Users\simpson\.m2\repository\org\springframework\spring-jcl\5.3.23\spring-jcl-5.3.23.jar" com.demo.EmployeeApiApplication
19:35:35.056 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader#4a79e7d6
2022-12-10 19:35:35,468 INFO com.demo.EmployeeApiApplication : Starting EmployeeApiApplication using Java 17.0.5 on DESKTOP-1J43AAP with PID 27224 (D:\Archive\_HR\Applications\Interview\ABN Amro\assignment\solution\employee-api\target\classes started by simpson in D:\Archive\_HR\Applications\Interview\ABN Amro\assignment\solution\employee-api)
2022-12-10 19:35:35,468 DEBUG com.demo.EmployeeApiApplication : Running with Spring Boot v2.7.5, Spring v5.3.23
2022-12-10 19:35:35,469 INFO com.demo.EmployeeApiApplication : The following 1 profile is active: "production"
2022-12-10 19:35:36,533 INFO com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesBeanFactoryPostProcessor : Post-processing PropertySource instances
2022-12-10 19:35:36,549 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource configurationProperties [org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource] to AOP Proxy
2022-12-10 19:35:36,550 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource servletConfigInitParams [org.springframework.core.env.PropertySource$StubPropertySource] to EncryptablePropertySourceWrapper
2022-12-10 19:35:36,550 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource servletContextInitParams [org.springframework.core.env.PropertySource$StubPropertySource] to EncryptablePropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource Config resource 'class path resource [application.yml]' via location 'optional:classpath:/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource devtools [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-10 19:35:36,579 INFO com.ulisesbocchio.jasyptspringboot.filter.DefaultLazyPropertyFilter : Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter
2022-12-10 19:35:36,703 INFO com.ulisesbocchio.jasyptspringboot.resolver.DefaultLazyPropertyResolver : Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver
2022-12-10 19:35:36,704 INFO com.ulisesbocchio.jasyptspringboot.detector.DefaultLazyPropertyDetector : Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector
2022-12-10 19:35:36,923 INFO org.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-10 19:35:36,923 INFO org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68]
2022-12-10 19:35:36,979 INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-10 19:35:37,053 INFO com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor : Found Custom Encryptor Bean org.jasypt.encryption.pbe.PooledPBEStringEncryptor#220275ac with name: jasyptStringEncryptor
2022-12-10 19:35:37,082 INFO org.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-12-10 19:35:37,114 ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.datasource.password' to java.lang.String:
Reason: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.password' to java.lang.String
Action:
Update your application's configuration
Process finished with exit code 0
I run the project using IntelliJ IDEA by selecting Run -> Edit Configurations and in the Build and run section, add the following value to the VM options field and run the application: -Djasypt.encryptor.password=my-secret
Try to downgrade to 2.0.0 version of jasypt-spring-boot-starter
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>

Spring Boot 2.3 fails to start when spring.jpa.hibernate.ddl-auto equals to validate

I have a Spring boot: 2.3.0.RELEASE application with Flyway: 6.4.1 and Hibernate: hibernate-core: 5.4.22.Final, hibernate-validator: 6.1.5.Final, hibernate-commons-annotations: 5.1.0.Final.
I tried searching for errors but cannot find a solution. I tried applying this answer, but whenever spring.jpa.hibernate.ddl-auto=validate is set, it doesn't work if I use none, drop-create value everything back to the norm.
I run MySQL 5.7 in Docker, and the database with tables is there.
The error is below:
ConfigServletWebServerApplicationContext : Exception encountered
during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'requestMappingHandlerAdapter' defined
in class path resource
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]:
Unsatisfied dependency expressed through method
'requestMappingHandlerAdapter' parameter 1; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'mvcConversionService' defined in class path
resource
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.format.support.FormattingConversionService]:
Factory method 'mvcConversionService' threw exception; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'customerRepository' defined in
org.cloudwheel.files.configuration.customer.persistence.CustomerRepository
defined in #EnableJpaRepositories declared on
JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot
resolve reference to bean 'jpaMappingContext' while setting bean
property 'mappingContext'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'jpaMappingContext': Invocation of init method
failed; nested exception is javax.persistence.PersistenceException:
[PersistenceUnit: default] Unable to build Hibernate SessionFactory;
nested exception is
org.hibernate.tool.schema.spi.SchemaManagementException:
Schema-validation: missing table [my_files]
How can I debug this? I see many such issues, but none of the solutions worked for me.
NOTE: The table my_files is present. I can verify this both via IntelliJ and MySQL Workbench. Also, I don't want to downgrade if possible.
UPDATE:
I am sure that a database isn't a problem:
2020-12-01 14:24:04.795 INFO 23295 --- [ restartedMain]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with
port(s): 8080 (http) 2020-12-01 14:24:04.800 INFO 23295 --- [
restartedMain] o.apache.catalina.core.StandardService : Starting
service [Tomcat] 2020-12-01 14:24:04.800 INFO 23295 --- [
restartedMain] org.apache.catalina.core.StandardEngine : Starting
Servlet engine: [Apache Tomcat/9.0.35] 2020-12-01 14:24:04.895 INFO
23295 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] :
Initializing Spring embedded WebApplicationContext 2020-12-01
14:24:04.895 INFO 23295 --- [ restartedMain]
o.s.web.context.ContextLoader : Root WebApplicationContext:
initialization completed in 1762 ms 2020-12-01 14:24:07.982 INFO
23295 --- [ restartedMain] o.f.c.internal.license.VersionPrinter :
Flyway Community Edition 6.4.1 by Redgate 2020-12-01 14:24:07.986
INFO 23295 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource
: HikariPool-1 - Starting... 2020-12-01 14:24:08.090 INFO 23295 --- [
restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1
Start completed. 2020-12-01 14:24:08.113 INFO 23295 --- [ restartedMain] o.f.c.internal.database.DatabaseFactory : Database:
jdbc:mysql://localhost:3307/files (MySQL 5.7) 2020-12-01 14:24:08.186
INFO 23295 --- [ restartedMain] o.f.core.internal.command.DbValidate
: Successfully validated 13 migrations (execution time 00:00.029s)
2020-12-01 14:24:08.199 INFO 23295 --- [ restartedMain]
o.f.core.internal.command.DbMigrate : Current version of schema
files: 1.13 2020-12-01 14:24:08.200 INFO 23295 --- [
restartedMain] o.f.core.internal.command.DbMigrate : Schema
files is up to date. No migration necessary. 2020-12-01
14:24:08.268 INFO 23295 --- [ restartedMain]
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing
ExecutorService 'applicationTaskExecutor' 2020-12-01 14:24:08.281
INFO 23295 --- [ restartedMain] o.s.s.c.ThreadPoolTaskScheduler
: Initializing ExecutorService 'taskScheduler' 2020-12-01 14:24:08.330
INFO 23295 --- [ task-1]
o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing
PersistenceUnitInfo [name: default] 2020-12-01 14:24:08.374 INFO
23295 --- [ task-1] org.hibernate.Version :
HHH000412: Hibernate ORM core version 5.4.22.Final
The exception says org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [my_files].
You say that the database my_files is present, but hibernate needs a table my_files to be present - for example you used annotation #Table(name = "my_files") or you have entity with name MyFiles.
Check whether the database contains the table my_files.
As #M.Deinum mentioned in his comments Flyway and Hibernate might not have been connected to the same datasource. In my case, it was because of hibernate.temp.use_jdbc_metadata_defaults=true. As soon as I removed this property, everything started working.

Maven dependency - postgres to Oracle

So far I was using Postgres on my localhost to run as my DB. Everything was ok, I had this dependency in my pom.xml and the following config (note that I didn't have the Driver specified explicitely):
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
application.configuration:
spring.datasource.url=jdbc:postgresql://*********
spring.datasource.username=********
spring.datasource.password=*********
All good:
2020-10-31 13:47:03.078 INFO 28600 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2020-10-31 13:47:04.037 INFO 28600 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8091 (http) with context path ''
2020-10-31 13:47:04.270 INFO 28600 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-10-31 13:47:04.283 INFO 28600 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-10-31 13:47:04.659 INFO 28600 --- [ main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-10-31 13:47:04.915 INFO 28600 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-10-31 13:47:04.925 INFO 28600 --- [ main] c.a.u.f.FetcherserviceApplication : Started FetcherserviceApplication in 8.87 seconds (JVM running for 10.334)
Now I wanted to switch to an oracle DB, so I've deleted the above postgresql dependency from my pom.xml and added one for Oracle plus deleted the postgres lines from my configuration and added the following:
spring.datasource.url=jdbc:oracle:thin:#********
spring.datasource.username=********
spring.datasource.password=*********
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.datasbase-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.hibernate.ddl-auto=update
Now, if at this point I try to rerun the application I see that the Oracle Driver is being picked up but then the application still fails to start after because:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-31 14:29:30.746 ERROR 6384 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driver-class-name
Value: org.postgresql.Driver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
Where is this coming from? I did updated the configuration as described above but more importantly the project shouldn't even know at this point that Postgres ever existed as as I've purged it from the pom.xml. So how is it possible there is an issue with it here?
I assume there is still something I don't understand about how Maven manages dependencies.
Thanks!
/András
This is due to the maven unable to import oracle dependencies automatically. Following will help you to resolve the issue
Remove PostgreSQL dependencies from the pom.xml
Then add oracle JDBC dependencies to the pom.xml
https://mvnrepository.com/artifact/com.oracle/ojdbc14
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
Download oracle dependencies and install manually to maven local repository
mvn install:install-file -Dfile="Your downloaded oracle jar file location" -DgroupId=com.oracle.ojdbc -DartifactId="artifact id" -Dversion="downloaded version number" -Dpackaging=jar
Then clean your project and run. It seemed to work.
You should use the latest 19.8 JDBC driver. Refer to this guide for more details.
Also, you can use DataSourceSample.java to verify if everything works fine.
<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8-production</artifactId>
<version>19.8.0.0</version>
<type>pom</type>
</dependency>
</dependencies>

Application is working as expected but when i conterize app with Docker it cannot access Cassandra container

I got a problem with my application. Everything has been working fine till I conterized App with Docker.
I Have Docker container with Cassandra instance in there docker run -p 9042:9042 --name cassandra cassandra:latest
*When I run my app in IntelliJ or run by cmd java -jar myjar.jar it works fine. The problem occurs when
I trying to use Docker or Docker-compose to start the app docker run -p 8080:8080 --name api {image here} or docker-compose up
Docker File:
FROM openjdk:8
COPY . /target/myjar.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","target/myjar.jar"]
Docker-Compose
version: '3'
services:
app:
build: ./app
ports:
- "8080:8080"
depends-on:
-cassandra
cassandra:
container_name 'cassandra'
image: cassandra
ports:
- "9042:9042"
What I have tried to solve the problem:
changing application ports
building docker and docker-compose file in diffrent way.
application.properties
spring.data.cassandra.keyspace-name=message
spring.data.cassandra.schema-action=create_if_not_exists
spring.data.cassandra.contact-points=127.0.0.1
spring.data.cassandra.port=9042
the error when I try to run container from image (Fragment)
2020-06-13 11:42:53.320 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive Cassandra repositories in DEFAULT mode.
2020-06-13 11:42:53.379 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 51ms. Found 0 Reactive Cassandra repository interfaces.
2020-06-13 11:42:53.387 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Cassandra repositories in DEFAULT mode.
2020-06-13 11:42:53.406 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 18ms. Found 1 Cassandra repository interfaces.
2020-06-13 11:42:54.030 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-06-13 11:42:54.050 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-06-13 11:42:54.050 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2020-06-13 11:42:54.146 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-06-13 11:42:54.146 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1734 ms
2020-06-13 11:42:54.611 INFO 1 --- [ main] c.d.o.d.i.core.DefaultMavenCoordinates : DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.6.1
2020-06-13 11:42:55.364 INFO 1 --- [ s0-admin-0] c.d.oss.driver.internal.core.time.Clock : Using native clock for microsecond precision
2020-06-13 11:42:55.371 INFO 1 --- [ s0-admin-0] c.d.o.d.i.core.metadata.MetadataManager : [s0] No contact points provided, defaulting to /127.0.0.1:9042
2020-06-13 11:42:55.567 WARN 1 --- [ s0-admin-1] c.d.o.d.i.c.control.ControlConnection : [s0] Error connecting to Node(endPoint=/127.0.0.1:9042, hostId=null, hashCode=530346a1), trying next node (ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (java.nio.channels.ClosedChannelException))
2020-06-13 11:42:55.586 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'messageApi' defined in URL [jar:file:/asrecruitment-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/mycompany/asrecruitment/api/MessageApi.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'messageService' defined in URL [jar:file:/asrecruitment-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/mycompany/asrecruitment/service/MessageService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageRepo' defined in com.mycompany.asrecruitment.repository.MessageRepo defined in #EnableCassandraRepositories declared on CassandraRepositoriesRegistrar.EnableCassandraRepositoriesConfiguration: Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfig': Invocation of init method failed; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=/127.0.0.1:9042, hostId=null, hashCode=530346a1): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (java.nio.channels.ClosedChannelException)]
2020-06-13 11:42:55.590 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-06-13 11:42:55.613 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-13 11:42:55.636 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'messageApi' defined in URL [jar:file:/asrecruitment-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/mycompany/asrecruitment/api/MessageApi.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'messageService' defined in URL [jar:file:/asrecruitment-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/mycompany/asrecruitment/service/MessageService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageRepo' defined in com.mycompany.asrecruitment.repository.MessageRepo defined in #EnableCassandraRepositories declared on CassandraRepositoriesRegistrar.EnableCassandraRepositoriesConfiguration: Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfig': Invocation of init method failed; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=/127.0.0.1:9042, hostId=null, hashCode=530346a1): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (java.nio.channels.ClosedChannelException)]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
at com.mycompany.asrecruitment.app.main(app.java:12) [classes!/:0.0.1-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) [asrecruitment-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:109) [asrecruitment-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) [asrecruitment-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) [asrecruitment-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'messageService' defined in URL [jar:file:/asrecruitment-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/mycompany/asrecruitment/service/MessageService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageRepo' defined in com.mycompany.asrecruitment.repository.MessageRepo defined in #EnableCassandraRepositories declared on CassandraRepositoriesRegistrar.EnableCassandraRepositoriesConfiguration: Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfig': Invocation of init method failed; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=/127.0.0.1:9042, hostId=null, hashCode=530346a1): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (java.nio.channels.ClosedChannelException)]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1306) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
... 28 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageRepo' defined in com.mycompany.asrecruitment.repository.MessageRepo defined in #EnableCassandraRepositories declared on CassandraRepositoriesRegistrar.EnableCassandraRepositoriesConfiguration: Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfig': Invocation of init method failed; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=/127.0.0.1:9042, hostId=null, hashCode=530346a1): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (java.nio.channels.ClosedChannelException)]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:342) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1699) ~[spr
** Proper run java -jar **
2020-06-13 13:35:19.461 INFO 12088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive Cassandra repositories in DEFAULT mode.
2020-06-13 13:35:19.593 INFO 12088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 116ms. Found 0 Reactive Cassandra repository interfaces.
2020-06-13 13:35:19.609 INFO 12088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Cassandra repositories in DEFAULT mode.
2020-06-13 13:35:19.630 INFO 12088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 23ms. Found 1 Cassandra repository interfaces.
2020-06-13 13:35:21.111 INFO 12088 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-06-13 13:35:21.134 INFO 12088 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-06-13 13:35:21.134 INFO 12088 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2020-06-13 13:35:21.296 INFO 12088 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-06-13 13:35:21.296 INFO 12088 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3376 ms
2020-06-13 13:35:21.945 INFO 12088 --- [ main] c.d.o.d.i.core.DefaultMavenCoordinates : DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.6.1
2020-06-13 13:35:22.985 INFO 12088 --- [ s0-admin-0] c.d.oss.driver.internal.core.time.Clock : Using native clock for microsecond precision
2020-06-13 13:35:22.985 INFO 12088 --- [ s0-admin-0] c.d.o.d.i.core.metadata.MetadataManager : [s0] No contact points provided, defaulting to /127.0.0.1:9042
2020-06-13 13:35:23.961 INFO 12088 --- [ s0-io-0] c.d.o.d.i.core.channel.ChannelFactory : [s0] Failed to connect with protocol DSE_V2, retrying with DSE_V1
2020-06-13 13:35:23.979 INFO 12088 --- [ s0-io-1] c.d.o.d.i.core.channel.ChannelFactory : [s0] Failed to connect with protocol DSE_V1, retrying with V4
2020-06-13 13:35:24.387 INFO 12088 --- [ s0-io-2] c.d.oss.driver.api.core.uuid.Uuids : PID obtained through native call to getpid(): 12088
2020-06-13 13:35:26.186 INFO 12088 --- [ s1-admin-0] c.d.oss.driver.internal.core.time.Clock : Using native clock for microsecond precision
2020-06-13 13:35:26.186 INFO 12088 --- [ s1-admin-0] c.d.o.d.i.core.metadata.MetadataManager : [s1] No contact points provided, defaulting to /127.0.0.1:9042
2020-06-13 13:35:26.214 INFO 12088 --- [ s1-io-0] c.d.o.d.i.core.channel.ChannelFactory : [s1] Failed to connect with protocol DSE_V2, retrying with DSE_V1
2020-06-13 13:35:26.231 INFO 12088 --- [ s1-io-1] c.d.o.d.i.core.channel.ChannelFactory : [s1] Failed to connect with protocol DSE_V1, retrying with V4
2020-06-13 13:35:30.078 INFO 12088 --- [ s2-admin-0] c.d.oss.driver.internal.core.time.Clock : Using native clock for microsecond precision
2020-06-13 13:35:31.698 INFO 12088 --- [ s2-admin-0] c.d.o.d.i.core.metadata.MetadataManager : [s2] No contact points provided, defaulting to /127.0.0.1:9042
2020-06-13 13:35:31.720 INFO 12088 --- [ s2-io-0] c.d.o.d.i.core.channel.ChannelFactory : [s2] Failed to connect with protocol DSE_V2, retrying with DSE_V1
2020-06-13 13:35:31.732 INFO 12088 --- [ s2-io-1] c.d.o.d.i.core.channel.ChannelFactory : [s2] Failed to connect with protocol DSE_V1, retrying with V4
2020-06-13 13:35:32.618 INFO 12088 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-06-13 13:35:32.943 INFO 12088 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-06-13 13:35:32.946 INFO 12088 --- [ main] com.mycompany.asrecruitment.app : Started app in 16.206 seconds (JVM running for 17.064)
The problem here is your application isn't connecting with the Cassadra's DB image.
2020-06-13 11:42:55.567 WARN 1 --- [ s0-admin-1]
c.d.o.d.i.c.control.ControlConnection : [s0] Error connecting to
Node(endPoint=/127.0.0.1:9042, hostId=null, hashCode=530346a1), trying
next node (ConnectionInitException: [s0|control|connecting...]
Protocol initialization request, step 1 (OPTIONS): failed to send
request (java.nio.channels.ClosedChannelException))
Fist, in your docker-compose.yml, you need to create an environment variable to be the cassandra host and then set your application.properties.
Docker-compose.yml
version: '3'
services:
app:
build: ./app
ports:
- "8086:8080"
depends-on:
-cassandra
cassandra:
container_name 'cassandra'
image: cassandra
ports:
- "9044:9042"
environment:
- CASSANDRA_HOST=cassandra
P.S. You can change the first port number to not confuse, but it's not a mistake.
application.properties
spring.data.cassandra.keyspace-name=message
spring.data.cassandra.schema-action=create_if_not_exists
spring.data.cassandra.contact-points=${CASSANDRA_HOST}
spring.data.cassandra.port=9042
It is important to check the cluster's name (spring.data.cassandra.cluster = <name>) in the cassandra.yaml inside the cassandra's image. It should be the same as in your application's image.

Spring Boot Start Up

Im trying to learn spring and the tutorial asked me to run mvn spring-boot:run.
However, i have the following error message(I attached a snippet). Please advise. All i have done is create a project from spring.io 's website then run mvn spring-boot:run
2019-11-30 14:45:03.338 INFO 14260 --- [ restartedMain] com.portal.VPortal.VPortalApplication : Starting VPortalApplication on Max with PID 14260 (C:\Users\Max\Documents\VPortal\target\classes started
by Max in C:\Users\Max\Documents\VPortal)
2019-11-30 14:45:03.338 INFO 14260 --- [ restartedMain] com.portal.VPortal.VPortalApplication : No active profile set, falling back to default profiles: default
2019-11-30 14:45:03.368 INFO 14260 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-11-30 14:45:03.368 INFO 14260 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-11-30 14:45:04.029 INFO 14260 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.spri
ngframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-30 14:45:04.329 INFO 14260 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-11-30 14:45:04.335 INFO 14260 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-11-30 14:45:04.335 INFO 14260 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-11-30 14:45:04.386 INFO 14260 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-11-30 14:45:04.386 INFO 14260 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1018 ms
2019-11-30 14:45:04.477 ERROR 14260 --- [ restartedMain] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message:
Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServle
tEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframewo
rk.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error c
reating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through metho
d 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/sprin
gframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed
to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.Unsatisfie
dDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration': Unsatisfied dependency expressed through constructor par
ameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/Da
taSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariData
Source]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.postgres.Driver
2019-11-30 14:45:04.493 INFO 14260 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-11-30 14:45:04.500 WARN 14260 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.conte
xt.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2019-11-30 14:45:04.510 INFO 14260 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-11-30 14:45:04.520 ERROR 14260 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
I found the error. In my application.yml, file I changed the org.postgres.Driver to org.postgresql.Driver .

Categories