parsing error in yml file for microservices - spring-boot

18:01:39.008 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.yaml.snakeyaml.scanner.ScannerException: mapping values are not allowed here
in 'reader', line 16, column 16:
uri: lb://USER-SERVICE
`
server:
port: 9190
spring:
application:
name: API-Gateway
cloud:
gateway:
routes:
- id: user-service
uri: lb://DEPT-SERVICE
predicates:
- path=/user/**
- id: dept-service
uri: lb://USER-SERVICE
predicates:
- path=/departments/**
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
instance:
preferIpAddress: true
`

Your yaml is not valid. Check this validator as example.
Note how on line 16 and next, uri, predicates and path are not on the same column as just before.
Valid yaml is:
server:
port: 9190
spring:
application:
name: API-Gateway
cloud:
gateway:
routes:
- id: user-service
uri: lb://DEPT-SERVICE
predicates:
- path=/user/**
- id: dept-service
uri: lb://USER-SERVICE
predicates:
- path=/departments/**
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
instance:
preferIpAddress: true

Related

I am getting error like main] ironmentPostProcessorApplicationListener : Your Okta Issuer URL is missing. in spring boot app

here is my .yaml file
server:
port: 9090
okta:
oauth2:
issuer: https://dev-#####.okta.com/oauth2/default
client-id: 0*********
client-secret: ******************
scopes: openid, profile, email, offline_access
spring:
application:
name: API-GATEWAY
config:
import: configserver:http://localhost:9296
cloud:
gateway:
routes:
- id: Order-service-app
uri: lb://Order-service-app
predicates:
- Path=/order/**
- id: PAYMENT-SERVICE-APP
uri: lb://PAYMENT-SERVICE-APP
predicates:
- Path=/payment/**
- id: Product-service-app
uri: lb://Product-service-app
predicates:
- Path=/product/**

org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple key

server:
port: 9191
--
cloud:
gateway:
routes:
- id : USER-SERVICE
uri : lb://USER-SERVICE
predicates :
- Path=/users/**
- id: DEPARTMENT-SERVICE
uri: lb://DEPARTMENT-SERVICE
predicates:
- Path=/departments/**
--
spring:
application:
name: API-GATEWAY
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultzone: http://localhost:8761/eureka/
instance:
hostname: localhost

Failed to bind properties under 'eureka.client.enabled' to boolean

why is the new spring-cloud-config so complicated?
I would like to do the following: enable eureka on default and add it in some profiles (not in all).
no matter in which way I tried it, it didn't work.
I get this error Failed to bind properties under 'eureka.client.enabled' to boolean.
first way:
server:
port: 8080
eureka:
client:
enabled: false # default disabled
instance:
leaseRenewalIntervalInSeconds: 10
prefer-ip-address: false
hostname: 127.0.0.1
spring:
application:
name: app
main:
banner-mode: off
cloud:
config:
enabled: false
discovery:
enabled: true
service-id: config-server
fail-fast: true
retry:
max-attempts: 5
application:
value: app-default
---
spring:
config:
activate:
on-profile: dev
application:
value: app-dev
---
spring:
config:
activate:
on-profile: qa
import: "configserver:"
cloud:
config:
enabled: true
eureka:
client:
enabled: true # enable it in profile "qa"
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
application:
value: app-qa
second way:
server:
port: 8080
eureka:
client:
enabled: true # default enabled
instance:
leaseRenewalIntervalInSeconds: 10
prefer-ip-address: false
hostname: 127.0.0.1
spring:
application:
name: app
main:
banner-mode: off
cloud:
config:
enabled: false
discovery:
enabled: true
service-id: config-server
fail-fast: true
retry:
max-attempts: 5
application:
value: app-default
---
spring:
config:
activate:
on-profile: dev
eureka:
client:
enabled: false # disable in profile "dev"
application:
value: app-dev
---
spring:
config:
activate:
on-profile: qa
import: "configserver:"
cloud:
config:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/ # I also need a profile specific url
application:
value: app-qa
if I activate eureka once and never use eureka.client.enabled again, then the error with the url occurs: Failed to bind properties under 'eureka.client.serviceUrl. defaultZone' to String - but I need this profile specific url in any case!
all this has to do with the new spring-cloud-config. because after I deleted all the lines for the config-server and commented out the spring-cloud-starter-config dependency, both variants with eureka worked!
or do i have an error according to this spring-cloud-config stuff?
versions:
<spring-boot.version>2.5.2</spring-boot.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>

Spring gateway - how to strip prefix for all routes only once

I am using configuration mode. Where is multiple (20) routes. But my server is accessible behind the URL PATH prefix http://prefixHere/method:port?property=value due Firewall and this can not be changed.
So when I have 20 of different methods (each ends in other service) then I must define 20 times.
I want to define the StripPrefix only once. This was working in previous Zuul gateway. How to do in cloud gateway?
Here is my config:
spring:
cloud:
gateway:
discovery:
locator:
lower-case-service-id: true
enabled: true
routes:
- id: auth-service
uri: lb://server-auth
predicates:
- Path=/prefixHere/auth/**
filters:
**- StripPrefix=1**
- id: operation-service
uri: lb://operation-service
predicates:
- Path=/prefixHere/operation/**
filters:
**- StripPrefix=1**
Yes, use "default-filters:" and it will be applied to all routes at once.
spring:
application:
name: gateway
cloud:
gateway:
default-filters:
- StripPrefix=1
E.g:
spring:
application:
name: GATEWAY-SERVICE
cloud:
gateway:
default-filters:
- StripPrefix=1
discovery:
locator:
enabled: true
lowerCaseServiceId: true
routes:
- id: department-service
uri: lb://department-service
predicates:
- Path=/api/departments/**
- id: user-service
uri: lb://USER-SERVICE
predicates:
- Path=/api/users/**
Reference: Introduction to spring cloud gateway

Spring cloud config client Could not locate PropertySource

My config server use natie file system works fine and the dev profile configured contextPath: /config
spring:
application:
name: dcit-config
profiles:
active: native
management:
endpoints:
web:
exposure:
include: info, health, metrics
metrics:
export:
atlas:
enabled: true
---
spring:
profiles: native
application:
name: dcit-config
cloud:
config:
server:
native:
searchLocations: classpath:/config/
server:
port: 2003
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://dcit:dcit#localhost:1023/eureka
registry-fetch-interval-seconds: 10
---
spring:
profiles: dev
application:
name: dcit-config
cloud:
config:
server:
git:
uri: http://xxx/git/Arch/dcit.git
username: user
password: pass
searchPaths: dcit-config/src/main/resources/config/
clone-on-start: true
fail-fast: true
server:
port: 2002
contextPath: /config
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://dc:dc#localhost:1023/eureka
registry-fetch-interval-seconds: 10
The native profile serve configs like this url: http://hostname:2003/config/app-profile.yml and my client works fine.
But if I use dev profile the url http://hostname:2002/config/app-profile.yml also works, but my client got error:
java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
My client config:
spring:
application:
name: dcit-auth
profiles:
active: dev
cloud:
config:
fail-fast: true
discovery:
service-id: dcit-config
enabled: true
profile: ${spring.profiles.active}
label: ${spring.profiles.active}
---
spring:
profiles: dev
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://dc:dc#localhost:1023/eureka
registry-fetch-interval-seconds: 10
solved by remove contextPath: /config and label configure

Resources