why couldn't the configuration in bootstrap.yml work? - spring-cloud

bootstrap.yml & application.yml
zuul.SendResponseFilter.post.disable: true
zuul.SendErrorFilter.post.disable: true
zuul.TraceDebugPreFilter.post.disable: true
zuul.ServletDetectionFilter.pre.disable: true
It couldn't work because com.netflix.zuul.ZuulFilter#isFilterDisabled is false.
But when I set command line like:
-Dzuul.ServletDetectionFilter.pre.disable=true \
-Dzuul.SendResponseFilter.post.disable=true
Then com.netflix.zuul.ZuulFilter#isFilterDisabled is true.
what's the matter? how can I make the bootstrap.yml configuration work?
Dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>

Related

How to fix password problem with CockroachDB and Spring-Boot

I have a problem with spring-boot and cockroachDB. On my local machine runs cockraochDB and spring-boot. As soon as spring boot starts , i'm getting an exception. Cockroach runs in insecure mode.
application.yaml:
spring:
datasource:
url: jdbc:postgresql:localhost:26257/mydb?sslmode=disable
username: myuser
password:
jpa:
properties:
hibernate.dialect: org.hibernate.dialect.PostgreSQL94Dialect
show-sql: true
database-platform: org.hibernate.dialect.PostgreSQL94Dialect
hibernate:
ddl-auto: create
pom.xml section:
[...]
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependencies>
[...]
I created two users. One with no password and one with a password in database "mydb" on cockroachDB. Both are not working. Append "?sslmode=disable" to the url in spring.datasource.url also not working.
Exception without password:
org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided.
Exception with password:
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "myuser"
Thanks for any help
You have to use:// after postgressql in your datasource url.
Your datasource url should be
jdbc:postgresql://localhost:26257/mydb?sslmode=disable

pause enpoint is not available

I am using Finchley.SR1 with following cloud dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
I have enabled pause config like this
endpoints:
restart:
enabled: true
pause:
enabled: true
Still no pause and resume endpoint available is actuator like before
{"_links":{"self":{"href":"http://localhost:18182/actuator","templated":false},"archaius":{"href":"http://localhost:18182/actuator/archaius","templated":false},"auditevents":{"href":"http://localhost:18182/actuator/auditevents","templated":false},"beans":{"href":"http://localhost:18182/actuator/beans","templated":false},"health":{"href":"http://localhost:18182/actuator/health","templated":false},"conditions":{"href":"http://localhost:18182/actuator/conditions","templated":false},"configprops":{"href":"http://localhost:18182/actuator/configprops","templated":false},"env-toMatch":{"href":"http://localhost:18182/actuator/env/{toMatch}","templated":true},"env":{"href":"http://localhost:18182/actuator/env","templated":false},"info":{"href":"http://localhost:18182/actuator/info","templated":false},"loggers":{"href":"http://localhost:18182/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:18182/actuator/loggers/{name}","templated":true},"heapdump":{"href":"http://localhost:18182/actuator/heapdump","templated":false},"threaddump":{"href":"http://localhost:18182/actuator/threaddump","templated":false},"metrics":{"href":"http://localhost:18182/actuator/metrics","templated":false},"metrics-requiredMetricName":{"href":"http://localhost:18182/actuator/metrics/{requiredMetricName}","templated":true},"scheduledtasks":{"href":"http://localhost:18182/actuator/scheduledtasks","templated":false},"httptrace":{"href":"http://localhost:18182/actuator/httptrace","templated":false},"mappings":{"href":"http://localhost:18182/actuator/mappings","templated":false},"refresh":{"href":"http://localhost:18182/actuator/refresh","templated":false},"features":{"href":"http://localhost:18182/actuator/features","templated":false},"service-registry":{"href":"http://localhost:18182/actuator/service-registry","templated":false},"bindings-name":{"href":"http://localhost:18182/actuator/bindings/{name}","templated":true},"bindings":{"href":"http://localhost:18182/actuator/bindings","templated":false},"channels":{"href":"http://localhost:18182/actuator/channels","templated":false}}
The endpoint configuration properties have been changed since Spring Boot 2.0.
To enable /actuator/restart, /actuator/pause and /actuator/resume you need to use management.endpoint.restart.enabled=true.
Also don't forget to include these endpoints in management.endpoints.web.exposure.include.

Project build error: 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-config:jar is missing

I'm developing code from the link: https://howtodoinjava.com/spring-cloud/spring-cloud-config-server-git/ and when I updated the Spring Boot version 2.1.2.RELEASE pom.xml is giving me below error.
Project build error: 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-config:jar is missing.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
The best way is to add a property to define the version of all your spring-cloud dependencies like this:
<properties>
...
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
</properties>
and next add this dependency managment:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Spring cloud gateway hystrix not working

I am having issues getting hystrix to work with my route. things like re-write paths and load balancing are working but for some reason hystrix never trips. I am setting my timeouts very low and have a delay in a downstream service. Is there anything special you need to do to get hystrix working?
I am using spring-cloud-gateway with eureka and spring-cloud-config. Also, is there a way to debug when a route is not working? Like a log setting to see what is happening?
Here is my route:
spring:
cloud:
gateway:
routes:
# =====================================
- id: main-service
uri: lbl://main-service
predicates:
- Path=/main-service**
filters:
- Hystrix=mainservice
Here is my pom
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-
8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.M5</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>2.0.0.M2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Here is my Application class:
#EnableDiscoveryClient
#EnableHystrix
#SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
The only other class in the jar is this:
#Configuration
public class GatewayConfiguration {
#Bean
public DiscoveryClientRouteDefinitionLocator
discoveryClientRouteLocator(DiscoveryClient discoveryClient) {
return new DiscoveryClientRouteDefinitionLocator(discoveryClient);
}
}
I figured out the issue. It seems that if you add eureka discovery then it automatically add routes that match all the spring.application.names returned by your eureka server and these have the same order as the ones I defined using application name as the predicate. I was able to fix this by setting the order for my route to -1.
Not sure if there is a better way to do this but at least I know hystrix is working.
Thanks
Maybe you should use this dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

SpringCloud Eureka - simple client doesnt register

I have an Eureka Server where I want to register a very basic SpringBoot service. Unfortunately the service doesnt register although I tried to follow all the articles I could find.
Moreover when I check description of the DiscoveryClient (that gets autowired), I see "Spring Cloud No-op DiscoveryClient" which suggests (as per NoopDiscoveryClient.java source) that Eureka client library isnt found.
In pom I have
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
which if I am right should make sure that proper netflix libraries are in place. #EnableEurekaClient annotation is present. No errors on the console when starting the client, nothing interesting in the Eureka Server console logs.
This is the configuration from the application.yml:
eureka:
client:
serviceUrl:
defaultZone: ${vcap.services.eureka-service.credentials.uri:http://127.0.0.1:8761}/eureka/
Any suggestions are really welcomed as I am running out of ideas :)
http://start.spring.io is your friend. You need to use the starters.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.M5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
and
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Except #spencergibb's answer, in my case it also require <spring-cloud.version> inside the <properties>:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.M3</spring-cloud.version>
</properties>