Reputation: 11
This is application properties code,please check and tell me how to fix the error.
debug=true
server.port=9090
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
#create, update, create-drop, validate
spring.jpa.hibernate.ddl-auto=update
#file related all configurations
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
project.image=images/
#here we are allowing debug so that we can get every log related to security on console
logging.level.org.springframework.security=DEBUG
#spring.profiles.active will tell us which profile we are using
spring.profiles.active= prod
This is application-developer properties code
spring.datasource.url=jdbc:mysql://localhost:3306/blog_app_apis
spring.datasource.username =
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
This is application-production properties code
spring.datasource.url= jdbc:mysql://blog-db.cx8gwdujroiq.ap-south-1.rds.amazonaws.com:3306/blog_app_apis
spring.datasource.username = pankaj
spring.datasource.password=kicker12345
This is the error message:
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 (the profiles prod are currently active).
Upvotes: 1
Views: 768
Reputation: 321
Your production configuration is missing the database driver property, which you should clearly understand from the reason section in the exception message:
Reason: Failed to determine a suitable driver class
Since you have the application.properties file with the default configuration properties, you can use the fix suggested to you by the Spring framework:
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 (the profiles prod are currently active).
In order to fix the error for the production profile you need to add the following property to your application.properties file: spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
The resulting file should look like this:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
debug=true
server.port=9090
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
#create, update, create-drop, validate
spring.jpa.hibernate.ddl-auto=update
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
project.image=images/
#here we are allowing debug so that we can get every log related to security on console
logging.level.org.springframework.security=DEBUG
#spring.profiles.active will tell us which profile we are using
spring.profiles.active=prod
This will add the default database driver for all your profile. So be mindful to change this if some specific profile will use a database that differs from MySQL.
Updated:
You also have the incorrect name of the active profile. In your application.properties file you have a such line that sets the active profile of your application:
spring.profiles.active=prod
But your profile-based file is called application-production.properties
. The Spring framework has a such naming format for configuration properties files:
application-[PROFILE_NAME].properties
So you should also rename your application-production.properties
file to application-prod.properties
to match the value from the spring.profiles.active
property.
Upvotes: 1