Issue in Running Jar file of Spring boot Gradle - java

I am not able to run the jar file of Spring Boot Gradle which I had created with ./gradlew clean bootJar jacocoMergeAll
and when I run in intellij with run button, I am able to run it.
and below is my commands which I had ran with intellij VM options which ran successfully but with jar this command does not work when I run the Jar file.
Below vm option is working one
-Dspring.profiles.active=local -Dserver.port=8080 -Dajp.port=0 -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc -Dspring.datasource.username=system -Dspring.datasource.password=MyPasswd123 -Dspring.config.additional-location=file:/Users/myUser/codebase/config/ -Dlogging.config=file:/Users/myUser/codebase/config/logback-spring.xml
Below running jar is not Working
java -Dspring.profiles.active=local -jar demo-0.1.0-SNAPSHOT.jar -Dserver.port=8080 -Dajp.port=0 -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc -Dspring.datasource.username=system -Dspring.datasource.password=MyPasswd123 -Dspring.config.additional-location=file:/Users/myUser/codebase/config/ -Dlogging.config=file:/Users/myUser/codebase/config/logback-spring.xml
I have tried with both -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc and -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521/OraDoc but none of this worked
when I run above jar command I get below error of not find the url
***************************
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 local are currently active).
my config file are under this directoy:
/Users/myUser/codebase/config/application.yml
/Users/myUser/codebase/config/application-local.yml
content of application.yml
server:
tomcat:
connectionTimeout: 300000
management:
endpoint:
mappings:
enabled: true
spring:
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
datasource:
driver-class-name: oracle.jdbc.driver.OracleDriver
hikari:
minimum-idle: 5
maximumPoolSize: 20
idleTimeout: 30000
maxLifetime: 2000000
connectionTimeout: 30000
poolName: factory-data-pool
jpa:
hibernate:
use-new-id-generator-mappings: false
ddl-auto: none
database-platform: org.hibernate.dialect.Oracle12cDialect
content of application-local.yml
server:
port: 8080
spring:
datasource:
url: jdbc:oracle:thin:#localhost:1521:OraDoc
username: system
password: MyPasswd123
liquibase:
contexts: local
Can someone please guide me on what wrong I am doing here?

Related

spring.profiles.active not working for all profiles

In my spring boot application, I have multiple profiles as below:
application.yml
application-dev.yml
application-local.yml
application-qa.yml
application-prod.yml
Each profile will have its own datasource configured. For testing purpose, same datasource configuration are passed in all profiles.
In application.yml if I mention spring.profiles.active=dev it is connecting to DB successfully. But if I mention spring.profiles.active=local then on server startup local profile is getting active with below error
***************************
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 lcl are currently active).
Below configuration passed in all profiles excluding application.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
password: root
url: jdbc:mysql://localhost:3306/local_db?useSSL=false
username: root
jpa:
hibernate:
ddl-auto: update
show-sql: true
liquibase:
change-log: classpath:db/changelog/db.changelog-master.json

When restarting Spring Boot I see 'no profiles are currently active'

My Spring Boot version is 2.3.4-RELEASE. I configure DataSource this way in application-dev.yml:
spring:
profiles: dev
datasource:
master:
driver-class-name: com.mysql.jdbc.Driver
url: myUrl
slave:
driver-class-name: com.mysql.jdbc.Driver
url: myUrl
When I activate the 'dev' profile, I can start my Spring Boot container successfully, but when I restart it, I get this error:
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).
I tried to add the config: spring.datasource.url. It works, but I need to distinguish master and slave. How can I do that?
You must activate your profile using property spring.profiles.active
If you have database settings to be loaded from a particular profile
you may need to activate it (no profiles are currently active).
Read set the active Spring profiles to see how to do it

Failed to bind properties under '' to com.zaxxer.hikari

I'm doing Spring Security and I'm trying to connecte my API with database to get user Authentication.
I don't know the error.
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: com.mysql.cj.jdbc.Driver
Origin: "driverClassName" from property source "source"
Reason: com.mysql.cj.jdbc.Driver
Action:
Update your application's configuration
Process finished with exit code 1
It looks like HikariCP configuration issue. If you are using yml file for spring boot, the application.yml file should have the following contents.
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: <jdbc url specific to your database>
driver-class-name: <database url>
username: <username>
password: <password>
hikari:
idle-timeout: 10000
Please change the place holders as I have mention with angles <> as per the database.

I need to set active profile in spring boot app though maven command but its taking default profile

I have 3 environments in my application i.e dev, prod, test i for that i separate files like application-prod.yml,application-dev.yml,applicaton-test.yml and also application.properties i am running command -> mvn spring-boot:run -Dspring.profiles.active=prod but its taking profile as a default profile
application.properties
server.port=8002
application-prod.yml
--------------------------
spring:
jpa:
show-sql: true
properties:
hibernate: dialect:org.hibernate.dialect.Oracle10gDialect
ddl-auto: update
datasource:
username: scott
password: tiger
url: jdbc:oracle:thin:#localhost:1521:xe
driver-class-name: oracle.jdbc.OracleDriver
app:
message : This for DevEnvironment connect to Oracle
logging:
level:
org:
springframework:
web: DEBUG
If you are using maven command then try the following to set the profile :
mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar
The above command sets the run time spring profile through the maven plugin.
Official doc.

Spring Boot Application Hanging When Running on Command Line

I have a Spring Boot app that can not be run with a .yml config file.Below is the command that I run:
java -jar /opt/myAppFolder/myApp.war
I have a config folder withing the same location that I run my war file. And in that config,I have a application.yml file that application needs to retrieve some config:
security:
user:
password: password
logging:
level:
org.springframework.security: DEBUG
release:
sourceDir: /$ANY_DIR
targetDir: /$ANY_DIR
users:
- name: $ANY_NAME
pwd : $ANY_NAME
- name: $ANY_NAME
pwd : $ANY_NAME
mail:
host: $ANY_NAME
recipients: $ANY_NAME
subject: $ANY_NAME
body: $ANY_NAME
server:
port: 9000
spring:
profiles:
active: prod
Problem: Once I run the app on command line,the process just hangs.No output,no logging. I have tried to enable debug via command line. No avail.
If I put a file with properties extension,it works.However I want to use .yml since it is more convenient for me to have list of dynamic properties.And why nothing is displayed anway?
Any help appreciated.
Spring Boot Version:1.5.7
OS Version:Ubuntu 3.13.0-24-generic
Finally resolved it.
So here is the story:
I have contacted Spring Boot Team and they have recommended me to upgrade to version 1.5.8.RELEASE.
Once I did that,I had a different issue;application was not hanging anymore,but shutting down without logging anything.
And eventually it turned out to be an error in my logback-spring.xml file. It was malformatted.And in its "prod" profile,I did not have any console appender.Hence no output visible. So I have fixed my file and it started working.
More on my communication with Spring Boot Team:
https://github.com/spring-projects/spring-boot/issues/10711

Categories