I am newbie with Springboot .I am unable to make jar file of Springboot with Mysql to deploy in AWS using Eclipse IDE.
I create an application which work perfectly fine in Localhost and when i want to deploy it into the AWS I comment all my application.properties file which has code like
#spring.jpa.hibernate.ddl-auto=update
#spring.datasource.url=jdbc:mysql://localhost:3306/db_digitalprofile?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#spring.datasource.username=root
#spring.datasource.password=
#server.port=9090
#spring.jpa.show-sql = true
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
and make a new file named as application-prod.properties in src/main/resource with the code:
server.port=5000
spring.datasource.url=jdbc:mysql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
spring.datasource.username=${RDS_USERNAME}
spring.datasource.password=${RDS_PASSWORD}
spring.jpa.hibernate.ddl-auto=update
Now when i want to make a jar file from right click on project> Run As>Maven install to create a jar file it throw a error like:
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
java.lang.IllegalStateException: Failed to load ApplicationContext
I had also add following dependency in pom.xml
<configuration>
<finalName> digitalProfile</finalName>
</configuration>
Failed to determine a suitable driver class
You need to check the dependencies. No driver found meaning, driver jar is missing which will be used to connect to Database. mysql driver should be present in your pom file or whatever your build file is.
Add this on your application.properties and it should fix your issue.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Related
I've got two configuraiton files in my Quarkus app (version 2.15.3.Final):
application.properties
application-dev.properties
I run my application with:
quarkus dev
so the Quarkus dev profile is active, but when I try to read the properties inside application-dev.properties they are not found.
On the other hand, if I move the property into the main application.properties they are found.
What am I doing wrong?
I'm trying to figure out how the project works.
It uses Liquibase:
The problem is that the .yaml file is not in the classpath folder so it's not accessible.
Error:
How to let Spring Boot know where is the change-log?
Use property name as
spring.liquibase.changeLog
not
liquibase.changeLog
Before start explaining my issue, it's worth mentioning that although I am trying to work how to use Maven Jib plugin in conjunction with Spring Boot and Kubernetes, the issue is the same even if I try to use a normal docker.
I have used Kubernetes configMap to create the application.yml file and mount it as an external file to the Pod (/config/application.yml). The issue I have been facing is my application does not able to find the application.yml file and throw a typical exception:
ERROR [main] org.springframework.boot.SpringApplication: Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.example.Application]; nested exception is java.io.FileNotFoundException: class path resource [application.yml] cannot be opened because it does not exist
I have tried different approaches with Jib by using different arguments such as below.
<container>
<extraClasspath>/config/*</extraClasspath>
<args>
<arg>--spring.config.location=file:/config/application.yml</arg>
</args>
<jvmFlags>
<jvmFlag>-Dspring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,file:/config/</jvmFlag>
</jvmFlags>
</container>
None of them has worked for me. I have also tried to use the SPRING_CONFIG_NAME environment variable and set it to file:/config/application.yml for the pod, but still the same issue.
I can verify that the config file exists in the specified location and there are no permission issues (as far as I can tell).
Interestingly, when I create just an empty application.yml file in the default classpath (src/main/resources) then it passes the first verification and the application loads successfully (with using the actual values from /config/application), so whatever the issue is it is being impacted by an initial verification of Spring Boot before even passing the application file to the corresponding classes.
It turns out that the only item I need to have is the following:
<container>
<extraClasspath>/config</extraClasspath> <!-- No need to have * at the end -->
</container>
I am using SQL server 2016.
and my application.property file is
spring.datasource.data-username=DDS-NA/njain
spring.datasource.data-password=
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=photo-app
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
I am getting "Cannot load driver class: com.microsoft.sqlserver.jdbc.SQLServerDriver" error. could someone guide me?
Please download the drivers from here
Add the jar to your project
Right Click on project - > Build Path -> Configure Build Path - > Libraries -> Add External JARs
And add the integratedSecurity=true to JDBC URL: jdbc:sqlserver://<<Server>>:<<Port>>;databasename=<<DatabaseName>>;integratedsecurity=true
You don't have to specify username and password for Windows Authentication
I am trying use liquibase maven plugin to generate changelog xml file. I add plugin to my pom file like below.
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<configuration>
<propertyFile>web/src/main/resources/liquibase.properties</propertyFile>
<changeLogFile>web/src/main/resources/data/changelog/db.changelog-master.xml</changeLogFile>
</configuration>
</plugin>
I am using liquibase.properties:
url=jdbc:mysql://127.0.0.1:3306/recproject_test?
useUnicode=yes&characterEncoding=UTF-8
username=recproject
password=sample
classpath=/repository/mysql/mysql-connector-java/5.1.38/mysql-connector-
java-5.1.38.jar
changeLogFile=web/src/main/resources/data/changelog/db.changelog-1.0.0.xml
But when I run liquibase:generateChangeLog as a maven goal I get:
Error setting up or running Liquibase: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: com.mysql.cj.jdbc.Driver
I store /mysql-connector-java jar in External Libraries and classpath in liquibase.properites is a path to this file.
I've downloaded mysql-connector-java-5.1.38.jar from here but it doesn't contain com.mysql.cj.jdbc.Driver.
So you should use database driver com.mysql.jdbc.Driver or download newer version of driver if you want to use com.mysql.cj.jdbc.Driver .
Add driver=com.mysql.jdbc.Driver to your properties and if you comparing it to another MySql database then you'll need to also include referenceDriver=com.mysql.jdbc.Driver. It seems like Liquibase will default to the MySQL 8 driver unless you specify both the driver and referenceDriver