Error I am Getting after running sudo ./gradlew run :
Task :run FAILED
12:03:13.440 [main] ERROR com.zaxxer.hikari.HikariConfig - Failed to load driver class com.mysql.jdbc.Driver from HikariConfig class classloader jdk.internal.loader.ClassLoaders$AppClassLoader#3d4eac69
12:03:13.445 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [javax.sql.DataSource] could not be loaded: Error instantiating bean of type [javax.sql.DataSource]
How my Application.yml looks like :
micronaut:
application:
name: freshdb2
#datasources.default: {}
datasources:
default:
url: jdbc:mysql://localhost:3306/mydb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: root
password: ""
driverClassName: com.mysql.jdbc.Driver
You are missing driver, you should add dependency mysql-connector-java, for gradle add:
runtime group: 'mysql', name: 'mysql-connector-java', version: '8.0.13'
I was also getting the message:
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [javax.sql.DataSource]
I'm not using MySQL, just trying to unpick how to use JPA from Micronaut Data Guide and others using H2.
It turns out I had incorrectly copied the datasource properties into application.yml. The above message is all you get to tell you this.
In my case the back quotes in the following had become something else.
datasources:
default:
url: ${JDBC_URL:`jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE`}
username: ${JDBC_USER:sa}
password: ${JDBC_PASSWORD:""}
driverClassName: ${JDBC_DRIVER:org.h2.Driver}
dialect: ${JDBC_DIALECT:H2}
Related
I have some problem with starting microservice with cloud config on local machine:
In application.yml:
spring:
application:
name: my_servie
config:
import: 'configserver:'
profiles:
group:
env-prod-pg: postgres,log
I create application-local.yml, where add:
spring:
application:
name: mc-service-logistics-v2
config:
import: 'optional:configserver:'
and some other config updates,
in build.gradle I add:
tasks.register("bootRunLocal") {
group = "application"
description = "Runs the Spring Boot application with the local profile"
doFirst {
tasks.bootRun.configure {
systemProperty("spring.profiles.active", "local")
}
}
finalizedBy("bootRun")
}
but when I try to start app with gradle bootRunLocal I caught error:
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8888/my-service/local": Connection refused; nested exception is java.net.ConnectException: Connection refused
If I understand- application still want to use cloud config and can't start. If I comment
spring.config.import in application.yml- aplication started without any problem.
How to solve this problem? I don't want to push to repo my local config again)
Well, I create to application-.yml and application.yml ,where store current profile:
spring:
profiles:
active: prod
Not sure what I'm doing wrong here, but I have the following value that points to the URL of a micro service.
#Value("${url.dispenseRoot}")
private String dispenseRoot;
And I am setting up my dev profile in my application.yml file such:
---
spring:
datasource:
url: jdbc:h2:mem:test
username: sa
password: sa
driverClassName: org.h2.Driver
config:
activate:
on-profile: dev
mpesa:
host: sandbox.safaricom.co.ke
port: 443
url:
dispenseRoot: https://localhost:8844/dispense
---
Then, in accordance with my answer here: How do I activate a Spring Boot profile when running from IntelliJ?, I set up the spring boot profile on the run configuration as such:
And then run the following test to test my configuration:
#SpringBootTest
public class PaymentApplicationTests {
#Test
public void contextLoads() {
}
}
And I get:
... 111 more
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'url.dispenseRoot' in value "${url.dispenseRoot}"
Now, if I copy and paste the following lines:
url:
dispenseRoot: https://localhost:8844/dispense
Above my profile where I'm setting up the general settings that are true for everything, it works fine. Therefore, I'm certain it has something to do with profiles, but I can't figure out what it is.
Please advise...
I want to write unit test in my Spring project.
There is only one application config in the whole project.
The application run well, but I get a "Caused by: java.sql.SQLException: No suitable driver" exception in unit test.
How can I setup a driver into the test?
The only annotation used in unit test:
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
The db connection settings in application.yml:
spring:
main:
allow-bean-definition-overriding: false
application:
name: application
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.sybase.jdbc4.jdbc.SybDriver
password: xxx
url: jdbc:sybase:Tds:localhost:3268/my_db
username: admin
hikari:
connection-test-query: SELECT 1
liquibase:
change-log: liquibase/changelog.sql
user: admin
password: xxx
jpa:
database: SYBASE
database-platform: org.hibernate.dialect.SybaseAnywhereDialect
hibernate:
ddl-auto: none
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
I finally find out the reason.
Since I had added a test configuration class into test folder, the extra configuration is also loaded into the single annotation "#SpringBootTest" test and the db connection setup fail.
When I comment the #TestConfiguration in the extra test configuration class file, the test with single #SpringBootTest can work normally.
I'm able to connect to postgres using spring cloud config server with only bootstrap.yml file.
But I have multiple environments like dev,test and prod. So I want to create separate profiles for each environment(like bootstap-dev.properties) and change the url datasource url accordingly.
Can anyone please suggest me regarding the same ?
bootstrap.yml:
server:
port: 8081
spring:
application:
name: myapp
profiles:
active: jdbc
datasource:
url: jdbc:postgresql://localhost:5432/config_db
username: XXXX
password: XXXX
driverClassName: org.postgresql.Driver
cloud:
config:
server:
jdbc:
sql: SELECT key, value FROM properties WHERE application=? AND profile=? AND label=?;
order: 0
default-label: default
bus:
trace:
enabled: true
security:
user:
name: XXX
password: XXX
management:
endpoints:
web:
exposure:
include: bus-refresh,health
endpoint:
health:
show-details: always
It is easy to use in the spring cloud.
First, create an application.properties that content only follow like this spring.profiles.active=dev
Second, to modify your dev application.properties name to application-dev.properties.
Ok, then put them into your resources directory together.
Others, you can create another file of environments with different suffixes, such as application-test.properties or application-pro.properties..., and only change the active value to the suffix name. like this spring.profiles.active=test
My best to you.
I am trying to get run application.yml instead of application.properties. But it fails. Please help. The same thing works in application.properties.
My application.yml looks like this:
spring:
profiles: container
jpa:
show-sql: true
database: MYSQL
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
hibernate:
ddl-auto: update
datasource:
url: jdbc:mysql://mysql57:3308/hello_java
username: demo_java
password: 1234
driver-class-name: com.mysql.jdbc.Driver
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-03 10:40:26.671 ERROR 12600 --- [ 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