I've got mongo DB running on docker. To set username and password I set MONGO_INITDB_DATABASE, MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD variables.
And now on spring boot application a can use URI:
mongodb://username:password#host:27017/db_name?authSource=admin and it's working.
Now I want changed properties and it looks like:
spring:
data:
mongodb:
authentication-database: admin
host: host
database: db_name
password: password
port: 27107
username: username
Any ideas what is wrong?
springboot: 2.2.5
spring-boot-starter-data-mongodb-reactive
I found that on the documentation:
If you use the Mongo 3.0 Java driver, spring.data.mongodb.host and spring.data.mongodb.port are not supported. In such cases, spring.data.mongodb.uri should be used to provide all of the configuration.
So probably this is the problem and for now I just stay with the URI.
Related
When I am retrieving data from the oracle database in the Springboot project am getting a No Datasource Set error kindly help me on this. Refer logs to sort the issue and thanks in advance.
in your application.yaml you can put sopmething like this:
spring:
datasource:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost:1433;databaseName=MyDatabase;encrypt=false
username: sa
password: Passw0#rd
If you are using application.properties instead of yaml then u can change to have entries like below:
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=MyDatabase;encrypt=false
...
note that the driver and url values will have different values depending of your database provider. The example is for SQL Server
If you are trying to connect to an Oracle XE database instance then you don't specify the driver-class-name (remove that entry) and as url you can have url: jdbc:oracle:thin:#localhost:1521:XE
So i'm trying to create basic SpringBoot app with DB connectivity and here is my application.properties
spring.datasource.url=jdbc:mysql://sql.somehost.net:3306/thisismydbname
spring.datasource.username=sql9XXXXXX
spring.datasource.password=XXXXXXXX
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = update
I created a very basic SpringBoot app with Spring Data JPA and maybe Spring Web dependencies.
When I try to boot up the app, I get the following error
java.sql.SQLException: Access denied for user 'sql9XXXXXX'#'ip6x-xxx-xx-xxx.dc.dc.cox.net' (using password: YES)
When I try to connect to MySQL using MySQL Workbench externally this works fine. Also, it's very weird why it's trying to use my ISP Cox in the connection. I don't know how it picked up my ISP details. I do have the somehost.net where my MySQL is hosted.
This question already has answers here:
Spring Boot configure and use two data sources
(10 answers)
Closed 4 years ago.
I have a spring boot application that will be communicating with two databases (Cassandra and DB2). I'll be using spring data in this application.
Is it applicable to configure the data sources only in application.yml file, without writing java code. If so, how can I specify the dialect for each one?
Note: this application uses spring-data-cassandra for cassandra database and spring-data-jpa for db2 database.
For example:
spring:
datasource:
url: jdbc:db2://myRemoteHost:portNumber/MyDBName
username: username
password: password
driver-class-name: com.ibm.db2.jcc.DB2Driver
data:
cassandra:
cluster-name: cluster name
keyspace-name: keyspace name
port: myPortNumber
contact-points: host1.com
username: username
password: password
Note: This question is different from Spring Boot Configure and Use Two DataSources . My question is to know if it's applicable to configure the data sources only in application.yml file without doing it manually, while the other question explains how to do it manually.
I found that it's applicable for the case above, as the application uses spring-data-cassandra for cassandra database and spring-data-jpa for connecting to db2 database.
Spring boot is smart enough to figure out which repositories and entities are used by spring-data-jpa and which are used by spring-data-cassandra.
As long as you are using a different spring data type for each database, it' applicable.
I have generated a spring boot project using jHipster. I want to reduce the number of connections to the database so I have modified the application-prod.yml file by adding the maximumPoolSize tag like this
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password:
maximumPoolSize: 2
But when I try deploying the application I have 10 connections to the database. What am I doing wrong?
Thanks
With Spring Boot 1.4 the general properties have been reduced and moved to specific properties per DataSource provider (which is also explained in the reference guide and the release notes).
So instead of using spring.datasource.maximumPoolSize you should be using spring.datasource.hikari.maximumPoolSize
For a list of properties see the appendix.
In Spring-XD clustered environment, we are using Oracle as job repository datasource. Right now, this has been configured through servers.yml. But, we have to enable fast connection failover (FCF) for High availability (HA). Does current servers.yml support this? Or Is there a way to replace job repository data source with Oracle Pool DataSource with ONS configuration. Please advise me with any solution?
you should be able to configure your datasource like any spring datasource.
did you try configure the datasource like this http://docs.spring.io/spring-data/jdbc/docs/current/reference/html/orcl.failover.html ?
you have to include your configuration like
datasource:
url: jdbc:"jdbc:oracle:thin:#(description=(address_list=(address=(host=rac1)(protocol=tcp)(port=1521))(address=(host=rac2)(protocol=tcp)(port=1521)))(connect_data=(service_name=racdb1)))"
username: sa
password:
driverClassName: oracle.jdbc.driver.OracleDriver
validationQuery: select 1 from INFORMATION_SCHEMA.SYSTEM_USERS
fast-connection-failover-enabled:true
ONS-configuration="rac1:6200,rac2:6200"
Let me know if that works, I am curious :)