I'm trying to use a spring profile argument to run a jar file, the profile isn't working:
java -jar -Dspring.profiles.active="test" build/libs/moley2-0.0.1-SNAPSHOT.jar
Here is my application.yml file:
spring:
profiles: dev
server:
port:8000
---
spring:
profiles: test
server:
port:9000
The jar was created using gradle build in the projects root directory. Running the jar with the command provided starts on port 8080 so it seems like the profile isn't loading. I'm sure I'm missing something simple here as I'm new to gradle / spring. Thanks in advance for any suggestions.
The property server should be:
server:
port: 9000
Instead of:
server:
port:9000
A space is missing between the colon and the value.
Also notice that configuring the profile as:
spring:
profiles: dev
is deprecated since 2.4.0 version and should be replaced with:
spring:
config:
activate:
on-profile: dev
More info in the doc. Or a tutorial here.
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
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 have few environments. There are:
local
dev
test
qa
lod
prod
Everything clear if config server connects to all of them.
In my case I need configuration server per group:
under dev control
under qa control
near devops control
Groups are connected to permissions and different environments.
so I need for each client something like:
bootstrap.yml
# default configs for local, dev, test profiles
spring:
application:
name: discovery-service
cloud:
config:
uri: http://local-dev-test-configuration-server:8888
---
# **bootstrap-qa.yml**
spring:
profiles: qa
application:
name: discovery-service
cloud:
config:
uri: http://qa-configuration-server:8888
---
# **bootstrap-prod.yml**
spring:
profiles: prod,lod
application:
name: discovery-service
cloud:
config:
uri: http://lod-prod-configuration-server:8888
Where
local-dev-test-configuration-server would have access to local, dev and test server configurations;
qa-configuration-server would have access to qa configuration;
lod-prod-configuration-server would have access to prod and lod configurations only.
Question:
I researched spring boot documentation but I have not faced with bootstrap.yml profiling.
Which way I should follow to cover my needs (manage 3 different config servers and correspond profiles)?
I've detected ability to configure different git resources for same config server. Is this approach the best for my case (I also have to manage few repositories to keep required configs)? I do not think so. I need to have few config servers for different envs because of different visibility. Thus I need configure on each consumer config hostname depending profile.
There are two possible solutions to configure clients for spring-cloud-configuration-servers:
spring-boot supports profiles in bootstrap.yml, so configuration provided in question can be used as solution
spring:
application:
name: discovery-service
cloud:
config:
uri: http://local-dev-test-configuration-server:8888
---
spring:
profiles: qa
application:
name: discovery-service
cloud:
config:
uri: http://qa-configuration-server:8888
---
spring:
profiles: prod,lod
application:
name: discovery-service
cloud:
config:
uri: http://lod-prod-configuration-server:8888
In case you want to keep bootstrap.yml configuration as simple as it possible:
spring:
application:
name: discovery-service
cloud:
config:
uri: http://local-dev-test-configuration-server:8888
in this case solution is to use -Dspring.cloud.config.uri=http://localhost:8888 parameter overrides required property for example:
java -Dspring.profiles.active=localhost -Dspring.cloud.config.uri=http://localhost:8888 -jar ./target/discovery-service-0.0.1-SNAPSHOT.jar
P.S.
Approaches can be mixed.
I have a dead simple config server with following properties :
spring:
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: classpath:/configs
server:
port: 8888
In the src/main/resources folder i have a configs folder with a customer-service.yml file inside it containing the following config :
spring:
application:
name: customer-service
h2:
console:
enabled: true
server:
port: 8080
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
logging:
level:
com.netflix: WARN
The config server starts with no issue but issuing the following URL in the browser - http://localhost:8888/customer-service/master - returns the following response :
{"name":"customer-service","profiles":["master"],"label":null,"version":null,"state":null,"propertySources":[]}
There doesn't seem to be many examples out there of using a folder on the classpath to store configs. What am I doing wrong?
I just tried it with Spring 2.1.3 and it works as you have laid it out. Since you mentioned you are using Spring 2.2, there might have been a change or potentially a bug.
Update
Just for kicks, I tried it with 2.2.0.BUILD-SNAPSHOT and it works as well. Not sure what to say at this point.
Hi i have installed jhipster 4.1.1 and im trying to create microservice and gateway applications, im using jhipster-registry, the microservice start ok, the gateway start ok, but when im trying to load localhost:8080, i obtained blank page, and no error on log.
whats happen?
Application 'clothes' is running! Access URLs:
Local: http://localhost:8080
External: http://192.168.56.1:8080
Profile(s): [swagger, dev]
----------------------------------------------------------
2017-04-06 11:15:17.186 INFO 6344 --- [ restartedMain] com.anelsoftware.clothes.ClothesApp :
----------------------------------------------------------
Config Server: Connected to the JHipster Registry config server!
----------------------------------------------------------
2017-04-06 11:19:58.930 INFO 6344 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
No entities were generated
You have to install all dependency manager, package manager and build tools for successfully run the JHipster app ( mvn, nvm, npm, bower, gulp ) before "yo jhipster" process.
If you have choose not stable version of Angular on generating process you have to change it or regenerate app.
For start JHipster app correctly you have to start 1-BackEnd mvnw or gradlew and 2-FrontEnd => yarn start.
Definitely the problem is Angular Beta, run gateway from springboot run and yarn start and works fine, now if only run springboot run does not work, any idea how to solve this?
I experience blank page when using MySQL on development.
The localhost:8080 is only for API request. With Angular, you access it on a different port.
Go to webpack.dev.js
Change the port to 9060
plugins: [
new BrowserSyncPlugin({
host: 'localhost',
port: 9060, // change this into 9060
proxy: {
target: 'http://localhost:9060'
}
}, {
reload: false
}),
and then access it on localhost:9060
I have found this with the latest JHipster (4.1.* and Angular 5).
My solution was to regenerate the application and everything worked.