After the migration to Spring Boot 3 it's not possible to activate multiple profiles in profile specific files. Instead Profile Groups should be used.
Unfortunately I can't get them to work, here is the snippet from my yml config:
spring:
profiles:
group:
local: debuglogin, profile_a, profile_b, profile_c
I have tried this in application-local.yml. Did anyone had the same experience?
I've just found the issue. I was adding this code block in the profile specific file like application-local.yml instead it should be added in the application.yml:
spring:
profiles:
group:
local: debuglogin, profile_a
integration-test: debuglogin, profile_b
this should work if added in the application.yml but not in profile specific files.
Related
I have core like this:
application-dev.yml
app:
region: east
application-uat.uml
app:
region: south
Then I have a microservice with following yml files
application-dev.yml
direct:
url: http://test-${app.region}.com
application-uat.yml
direct:
url: http://test-${app.region}.com
I believe, my spring application should be able to read values from core but it's not reading values from core. What am I doing wrong here?
You have to change one of the two file name and the micorservice module must depend on core module. Then you can add in application-dev.yml or application-uat.yml of the microservice module
spring:
config:
import: classpath:core-dev.yml
I was updating microservice to the newest Springboot - for now it is 2.5.5 with cloud version 2020.0.4. However there were some changes related to connection with config server. Previously config server configuration looked like this:
spring:
cloud:
config:
uri: ${CONFIG_SERVER_URI:http://localhost:8888}
fail-fast: ${CONFIG_FAIL_FAST:true}
However now it's required to provide it this way:
spring:
config:
import: configserver:${CONFIG_SERVER_URI:http://localhost:8888}
And that would be perfectly fine, except I am not able to run microservice locally without connecting to config server.
Previously I did it like this:
spring:
cloud:
config:
enabled: false
And it was perfectly fine, I had separate application-local.yaml file and had what I wanted.
Now I tried this (according to what is said in documentation):
spring:
cloud:
config:
import-check:
enabled: false
enabled: false
config:
import: "optional:configserver:http://localhost:8888"
But once I run microservice locally, I get only single log like this:
Connected to the target VM, address: '127.0.0.1:59759', transport: 'socket'
And basically nothing more, seems like it keeps trying to connect to config server, because if I run config server and after this try to run my microservice, it's working fine. Additional weird thing is that IntelliJ is showing me that it doesn't recognize this import-check property.
As for dependencies I have only implementation 'org.springframework.cloud:spring-cloud-starter-config:3.0.5' related to config server.
Is there some way to run microservice locally so that it's not connecting to config server using Spring Boot 2.4+? I don't want to use bootstrapping and providing additional dependency, since there is no point to use legacy stuff.
Here is the configuration I have for application.yaml in /src/main/resources folder.
---
spring:
config:
activate:
on-profile: "!config-local"
import: configserver:http://config-server.example.com:8888/
cloud:
config.fail-fast: true
---
spring:
config:
activate:
on-profile: "config-local"
import: optional:configserver:http://localhost:8888/
cloud:
config:
enabled: false
And in Intellij IDEA Run config, I set the active Profile as config-local this works with Springboot 2.5.5 and
ext {
set('springCloudVersion', "2020.0.4")
}
I have application files according to my environment: application.yml and application-uat.yml. I'm running the application by providing the SPRING_PROFILES_ACTIVE as environment variable so that the correct file is selected. I have a problem with defining additional profiles inside application.
Suppose I have a bean with profile mock-rest that mocks the rest client and I have a bean with profile actual-rest.
I've tried two do it in those ways:
#inside application.yml
spring:
profiles:
include: mock-rest
And for UAT:
#inside application-uat.yml
spring:
profiles:
include: actual-rest
But the problem is that spring will include both profiles, because it takes the both files and only replaces the values from uat yml file.
If I try to use spring.profiles.active inside yml files Spring will ignore that as the SPRING_PROFILES_ACTIVE environment variable will have priority.
So, the question is what is the way to overcome described problem? Basically, I need to define profiles inside application.yml files and I want to only define environment as my SPRING_PROFILES_ACTIVE env variable. Is this possible? If not, what are my options to consider?
The application.yml file is read whatsoever. This is an indented behaviour. Usually, all values in application.yml would be overrided by other more specific application-*.yml.
But profiles are not a single values, you can have multiple one enabled at the same time, so i does not oeverride the profile, instead it cumulate both.
If you want to get rid of the mock-rest on prod environment you might want to remove the mock-rest profile from application.yml and move it to a new application-mock.yml that you can activate using an environment variable.
application.yml
# some default configuration
application-mock.yml
spring:
profiles:
include: actual-rest
application-uat.yml
spring:
profiles:
include: actual-rest
I build some simple spring boot project, with jpa/postgres.
But when i debug this project, error say
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
But in my application.properties that have url.
spring.datasource.url=jdbc:postgresql://localhost:5432/oauth?currentSchema=oauth
spring.datasource.username=SOME_USER_NAME
spring.datasource.password=SOME_PASSWORD
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=validate
#hibernate
spring.jpa.database = postgresql
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
Does anyone know about this?
if validation is trouble than debug don't say like 'url attribute is not specified'.
And My application.properties name 'application-test.properties', and in debug configuration set 'test', and also log say 'the profiles test are currently active'.
It looks like properties is not matching, but log said profile is matched.
It makes me very confuse..
I found problem. Jonathan Johx and TinyOS is right, Thanks for them.
If project built by spring boot 2.1.1, Intellij with postgres, then Override build.gradle and pom.xml.
In Spring-boot 2.1.1 (I still don't know why default value is it)
default setting is
runtime('org.postgresql:postgresql')
but If you want to run right, than must write 'compile' like this.
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
version is not important. just find in maven repo what you want version.
In Spring boot application, Need to configure Oracle RAC DB URL. Can someone explain how to configure the Oracle RAC URL in application.properties?
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL={PROTOCOL})(HOST={{URL})(PORT={PORT})))(CONNECT_DATA=(SERVICE_NAME={SERVICE_NAME})))
Have verified the Spring boot official doc and didn't find anything related. Even verified in the Common Properties and can't find any references.
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
Thanks for your help in advance!
Try with below.
jdbc:oracle:thin:#(DESCRIPTION=
# (LOAD_BALANCE=on)
# (ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521))
# (ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=1521))
# (CONNECT_DATA=(SERVICE_NAME=service_name)))
OR
# Oracle settings
spring.datasource.url=jdbc:oracle:thin:#localhost:1522:orcl
spring.datasource.username=HIBERNATE_TEST
spring.datasource.password=HIBERNATE_TEST
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver
OR
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=OFF)(FAILOVER=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db1.myco.com)(PORT=1604))
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db2.myco.com)(PORT=1604)))
(CONNECT_DATA=(SERVICE_NAME=mydb1.myco.com)(SERVER=DEDICATED)))
Sources :
https://docs.oracle.com/cd/E57185_01/EPMIS/apbs01s01.html
https://dzone.com/articles/configuring-spring-boot-for-oracle
This is what i did to connect to postgres in my project and it is in production now. For Oracle it is exactly same. In fact for any other RDBMS.
Add the properties in the application.yml or the application.properties in the spring boot project.
The below is yml configuration.
spring:
jpa:
database: POSTGRESQL
show-sql: false
datasource:
platform: postgres
url: jdbc:postgresql://123.3.4.89.com:1234/DatabaseName
username: user123
password: pass123
driver-class-name: org.postgresql.Driver
testWhileIdle: true
validationQuery: SELECT 1
Then add the driver in the pom or the gradle build file which build tool you are using.
And the jpa jar of spring boot.
This was entry in the build.gradle file.
compile ('org.springframework.boot:spring-boot-starter-data-jpa')
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.2'
Thats it, now you can create your repositories and start pushing and fetching data in the Db.
Hope this helps, cheers !!!