How to use zuul in spring cloud without spring boot actuator? - spring-boot

I want to use zuul as a proxy server in my application, but I don't want to use spring boot actuator, I tried to remove it from the dependency as follow:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>${spring-cloud-netflix.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</exclusion>
</exclusions>
</dependency>
However, it will cause some ClassNotFoundException.
I don't need spring boot actuator in my application, but it has so many autoconfiguration in spring boot that will produce many endpoints that I don't want.
Is there any good way to solve this?

The issue has been addressed in spring cloud netflix 1135. It will be available shortly in Brixton.SR2.

Related

Zipkin server is not showing Microservices trace

I have a Microservice A calling another Microservice B with the following pom.xml and application.properties values:
pom.xml
<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>
application.properties
spring.zipkin.base-url=http://localhost:9411/
spring.sleuth.sampler.probability=1.0
spring.zipkin.sender.type=web
spring.zipkin.collector.http.enabled=true
Zipkin server version: zipkin-server-2.12.9
Spring Boot Version: 2.7.5
Spring cloud version: 2021.0.4
Issue is that trace that Microservice A called Microservice B with the trace-ID is not getting displayed in Zipkin.
Any issue?
Trace of Microservices calling chain with trace-ID should be coming in Zipkin server
The problem was that RestTemplate used to call the another service was create as New.
Solution is that create it as a bean and inject it to your code.

implement circuit breaker with openfeign in spring-boot 2.4 and spring cloud 2020

If I want to upgrade to spring-boot 2.4 and spring cloud 2020.
Now that spring-cloud-starter-netflix-hystrix has been removed from spring-cloud-netflix,
How can I implement circuit breaker with openfeign?
I did a direct import but my IDE cannot resolve feign.hystrix.enabled and feign is not executing the fallback class.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.7.RELEASE</version>
</dependency>

Spring boot Kubernetes Service Discovery

I am running into issues with Kubernetes Service Discovery on Spring Boot applications.
I should be able to discover the services whether my spring boot application is running within or out of Kubernetes cluster. Our local development won't be on k8s cluster.
I am using Service Discovery via DNS. I tried using spring-cloud-starter-kubernetes
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes</artifactId>
<version>0.2.0.RELEASE</version>
</dependency>
As per documentation you should be able to autowire DiscoveryClient and good to go
#Autowire
private DiscoveryClient discoveryClient;
DiscoveryClient is part of spring-cloud-commons. spring-cloud-starter-kuberenetes doesn't have it.
Anyone solved similar problem using the same library or a different one? Please share the solution
Thanks!
I have solved this issue using the Spring Cloud Kubernetes Dependencies
<spring.cloud.kubernetes>0.2.0.RELEASE</spring.cloud.kubernetes>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-ribbon</artifactId>
<version>${spring.cloud.kubernetes}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-config</artifactId>
<version>${spring.cloud.kubernetes}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-core</artifactId>
<version>${spring.cloud.kubernetes}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
<version>${spring.cloud.kubernetes}</version>
</dependency>
What was very important for me was the ribbon dependency as it makes use of a load balanced rest template in order to substitute service names for the correct pod IP's that are found in your kubernetes cluster.
I have created a git repo as part of answering a larger set of questions but it should be more than sufficient if someone is looking a way to implement Kubernetes service discovery in place of Eureka or Consul.
https://github.com/foundery-rmb/kubernetes-service-discovery

Authenticating RestEnd Points with Okta and OAuth

We have a Java 8 backend application using SprintBoot with an embedded Jetty server.
The UI for the application is a thymeleaf UI.
Currently I have enabled authentication by integrating with Okta using the spring security SAML extension.
Now we have several REST endpoints in our backend and we would want them to be authenticated as well.
Upon reading, I started Okta OpenID Connect can be one choice which issues a JWT. However I am not clear on how to use this. How can I support both my SAML Authentication for Web UI and Authentication using OpenID Connect for my Rest Endpoint.
If your client (Thymeleaf) is in your Spring Boot application, I'd suggest using Stormpath's Spring Boot Starter. This will give you authentication for your UI and security for your REST endpoints. The 2.0.0-rc1 release is compatible with Okta. In your pom.xml, you'll need the following XML:
<properties>
<stormpath.version>2.0.0-okta-rc1</stormpath.version>
</properties>
<dependencies>
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-default-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.stormpath.sdk</groupId>
<artifactId>stormpath-bom</artifactId>
<version>${stormpath.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

How to add Spring Boot Actuator to a Spring application?

In the "Bootiful" Applications with Spring Boot Spring One 2014 section(https://www.youtube.com/watch?v=HCyYEVRZISk), Josh mentioned that it is easy to add the Boot Actuator to a Spring (non-bootiful) application. I assume that an Actuator configuration is needed somehow, but can't find how it shall be done.
Just add the starter to your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
... and the endpoints such as /health will be available.

Resources