Migrate #EnableCircuitBreaker and #EnableEurekaClient to Spring Cloud 2022.0.1 - spring

I upgraded Spring Cloud version to 2022.0.1 and I get error for imports not found:
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
Application class:
#EnableEurekaClient
#EnableCircuitBreaker
Do you know how I can properly import them or upgrade them?

since Spring boot 2.5.12 #EnableCircuitBreaker is Deprecated, So you don't need to use it.
Also, this happened to #EnableEurekaClient and there is no need to annotate it
Just add these two dependencies to the project
spring-cloud-starter-circuitbreaker-resilience4j
org.springframework.cloud:spring-cloud-starter-netflix-eureka-client

Related

How do I use the OpenTelemetry component in Apache Camel?

Using the Spring Boot example from Camel, I'm trying to set up OpenTelemetry to instrument Camel.
Based on the docs, I chose the Spring Boot Auto-configuration option and added the dependency to my pom.xml.
I've also annotated the main class with #CamelOpenTelemetry:
package sample.camel;
import org.apache.camel.opentelemetry.starter.CamelOpenTelemetry;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//CHECKSTYLE:OFF
/**
* A sample Spring Boot application that starts the Camel routes.
*/
#CamelOpenTelemetry
#SpringBootApplication
public class MyCamelApplication {
...
I started the application with OTEL_TRACES_EXPORTER=logging mvn spring-boot:run.
Is this correct? I'm not seeing any console output unlike this simple OpenTelemetry example.
I'm not sure if Camel 3.x is supported because this page says only 2.20+ is supported but Camel's docs says Since Camel 3.5 at the top.

Getting 405 - Method Not Allowed in Swagger (Spring Boot)

I'm getting a 405 - Method Not Allowed error when testing a GET method in Postman. In a browser, when trying to use swagger-ui I'm getting a Whitelabel Error Page.
I'm on Java 17, Spring Boot 2.7.3, and I'm using Swagger 3.0.
Here's the Swagger configuration. I've had to remove #Configuration because Spring Boot couldn't start when that annotation was in use and DocumentationType.OAS_30 is here instead of SWAGGER_2 because I'm using Swagger 3.0.
package hr.ogcs.blueprint;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
#EnableSwagger2
public class SwaggerConfig {
#Bean
public Docket api() {
return new Docket(DocumentationType.OAS_30).select()
.apis(RequestHandlerSelectors.basePackage("hr.ogcs.blueprint"))
.paths(PathSelectors.any()).build();
}
}
Here's a Gradle configuration. I've tried with springfox-boot-starter dependency, but the Spring Boot couldn't start with it. So I added swagger2 and swagger-ui dependencies.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'io.springfox:springfox-swagger2:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Here's a solution:
In order to solve this issue, I dropped the Springfox library and used another library named SpringDoc. The Springfox obviously still doesn't work with Swagger 3.0 so remove this from your Gradle:
implementation 'io.springfox:springfox-swagger2:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
The solution is quite simple.
Use this dependency instead, and everything will work like a charm:
`implementation` 'org.springdoc:springdoc-openapi-ui:1.6.11'
You don't need any additional Swagger Config file or any annotation. Now go to http://localhost:8080/swagger-ui.html to see the results.
I've followed this tutorial on Baeldung.

How do I get the #EnableOAuth2Sso annotation

Upgraded to Spring Boot 2, now the #EnableOAuth2Sso annotation is missing because the import is now incorrect.
I found some docs on this issue:
https://github.com/spring-projects/spring-boot/issues/11032#issuecomment-372100443
but it doesn't say what to replace the import with. Thanks!
Same issue and found you have to add the Spring Security OAuth2 AutoConfigure dependency.

How to configure JMX with Spring Boot

I have created a Spring Integration application with Spring Boot. I would like to know how to configure JMX with Spring Boot. I believe by default JMX is configured when using Spring Boot Actuator.
Do I need to configure anything else to be able to export MBeans for Spring Integration?
Most of the example I see have the following line in the applicationContext.xml
<context:mbean-export/>
<context:mbean-server/>
My Application.java class looks like this.
package com.jbhunt.app.consumerappointmentintegration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
#Configuration
#ComponentScan
#EnableAutoConfiguration
#ImportResource("classpath:META-INF/spring/integration/spring-integration-context.xml")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Adding this line to the configuration doesn't seem to export the Spring Integration mbeans
#EnableIntegrationMBeanExport(server = "mbeanServer", defaultDomain="my.company.domain")
I'm referencing this video https://www.youtube.com/watch?v=TetfR7ULnA8
As you understand the Spring Integration JMX is enabled by default, if you just have spring-integration-jmx in the classpath. And, of course, if spring.jmx.enabled = true (default).
You can't overrride that just declaring one more #EnableIntegrationMBeanExport, because it is based on #Import and you just can't override import classes because of (from ConfigurationClassParser):
imports.addAll(sourceClass.getAnnotationAttributes(Import.class.getName(), "value"));
If imported classes are already there, they aren't overridable.
You have several choices to achieve your requirements:
Disable default Spring Boot JMX - just addind to the application.properties spring.jmx.enabled = false and continue to use #EnableIntegrationMBeanExport
Configure IntegrationMBeanExporter #Bean manually.
Just configure your my.company.domain domain in the application.properties:
spring.jmx.default_domain = my.company.domain
It is quite late to add this; but in addition to the endpoints.jmx.domain I found it useful to change the spring.jmx.default-domain to someting unique per application
This is with multiple instances of Spring Boot 1.4.1 apps running in Tomcat 7

Spring #Bean annotation differences (context vs config packages)?

What is the difference between these classes and when should I use each in conjunction with #Configure?
org.springframework.context.annotation.Bean
org.springframework.config.java.annotation.Bean;
It looks like you have an obsolete jar file in your classpath - org.springframework.config.java.annotation.Bean is no longer with the latest Spring 3.1.2 jars, it is the org.springframework.context.annotation.Bean annotation that should be used with the #Configuration classes
The JavaConfig dependency is part of the spring-context as of Spring 3.0. Therefore if you are building your app using Spring > 3.0 use the org.springframework.context.annotation.Bean

Resources