Enable HttpTrace in SpringBoot 2.6.6 - spring-boot

I have migrated the service to Spring Boot 2.6.6 and I have this bean configured as follows:
#Bean
fun traceFilterRegistration(filter: HttpTraceFilter) {
val registration = FilterRegistrationBean(filter)
registration.urlPatterns = listOf("/prefix1/*", "/prefix2/*")
return registration
}
This throws an error:
No qualifying bean of type 'org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter'
I searched and found that this was removed as mentioned here and now requires Spring Cloud Sleuth. However after adding the Spring Cloud Sleuth dependency, I still get the above exception.
Any idea how to enable Http tracing again?

Related

Resilience4J Retry not auto-configured in Spring boot 3

I'm in the process of migrating to Spring Boot 3. In Spring Boot 2 Resilience4J Retry was auto-configured and worked out of the box using the following setup:
application.yaml:
resilience4j.retry:
instances:
some-instance
# retry config here
Test class:
#SpringBootTest
public class TestClass {
#Autowired
private RetryRegistry retryRegistry;
#Test
void someTest() {
// perform test and evaluate retries using retryRegistry
}
}
However while updating to Spring Boot 3 using the following versions:
org.springframework.boot:spring-boot-starter:jar:3.0.0:compile
io.github.resilience4j:resilience4j-spring-boot2:jar:1.7.0:compile (derived from a Spring BoM)
The test in which the RetryRegistry was autowired failed with the following message:
Unsatisfied dependency expressed through field 'retryRegistry':
No qualifying bean of type 'io.github.resilience4j.retry.RetryRegistry' available:
expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
I managed to fix the test by explicitly importing the Resilience4j Retry configuration in the test using:
#Import(io.github.resilience4j.retry.autoconfigure.RetryAutoConfiguration.class)
However, I'm wondering why the component scanning mechanism in Spring Boot 3 did not pick up the retry config in the first place. Would anyone know why Spring Boot 3 did not pick up the class during component scanning?
In the resilience4j project they changed the dependency for spring boot 3.
So you should go for io.github.resilience4j:resilience4j-spring-boot3:${resilience4jVersion}
like
org.springframework.boot:spring-boot-starter:jar:3.0.0:compile
io.github.resilience4j:resilience4j-spring-boot3:jar:2.0.0:compile
from the documentation
It seems that it is related to a new META-INF file being used instead of the old spring.factories file. From the documentation :
Spring Boot 2.7 introduced a new META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports file for registering auto-configurations, while maintaining backwards compatibility with registration in spring.factories. With this release, support for registering auto-configurations in spring.factories has been removed in favor of the imports file.
The Resilience4J dependency used in the spring-cloud-dependencies-parent BoM still uses a spring.factories file instead of the new file named org.springframework.boot.autoconfigure.AutoConfiguration.imports. The new file has recently been introduced in Resilience4J (source).
Overriding the version from the Spring BoM with version 2.0.2 for all the resilience dependencies fixed it for me. I will check in a few days whether the new Resilience4J version has been updated in the Spring BoM (or resilience4j-spring-boot3 has been introduced).
[edit]
As others have noticed,resilience4j-spring-boot3 is already available. I'll start using it.

why Spring boot 2.4.3 has migration issues related entityManagerFactory bean

I had a working application using spring boot 1.5.9
After i upgrade spring boot to latest 2.4.3, facing issues with
an interface with #Reposiroty - required a bean of type testRepository
then added #EnableJPAConfiguration to bootRunner got below error
required a bean named 'entityManagerFactory' that could not be found
If i a write LocalContainerEntityManagerFactoryBean bean with dataSource configuration, i could see the application starts.
I dont really see these details from this Migration Guide
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide
Kindly Please help me understanding this puzzle. Thank you.

"httptrace" endpoint of Spring Boot Actuator doesn't exist anymore with Spring Boot 2.2.0

With Spring Boot 2.2.0 the "httptrace" Actuator endpoint doesn't exist anymore. How can I get this functionality back?
The functionality has been removed by default in Spring Boot 2.2.0.
As a workaround, add this configuration to the Spring environment:
management.endpoints.web.exposure.include: httptrace
and provide an HttpTraceRepository bean like this:
#Configuration
// #Profile("actuator-endpoints")
// if you want: register bean only if profile is set
public class HttpTraceActuatorConfiguration {
#Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}
}
http://localhost:8080/actuator/httptrace works again.
You need to enable httptrace by having following application properties. By default it is disabled
management.trace.http.enabled: true
management.endpoints.web.exposure.include: httptrace
and Requires an HttpTraceRepository bean. You can use Your own Custom implementation or InMemoryHttpTraceRepository

Registering spring boot application with consul after service is bootup

I have a legacy code where a spring boot application is registered with consul after the service boot up. The application autowires ConsulLifecycle spring bean through which it register/un-register the service with consul using its inbuild method ConsulLifecycle.start() and ConsulLifecycle.stop().
Now we have upgraded spring to 5.1.5, spring-cloud-starter-consul-discovery to 2.1.1 and spring-cloud-dependencies to Greenwich.RELEASE in which ConsulLifecycle bean is removed. So for achieving the same behaviour, I am trying to autowire ConsulAutoServiceRegistration spring bean and using its start and stop method to register and unregister the service with consul.
The issue is now when I am trying to start the spring boot application I am getting some error on application boot up(error mentioned in the last section of the post).
Note: I have application.properties file where I have defined this property
spring.cloud.consul.host=127.0.0.1
spring.cloud.consul.port=8500
##Embedded Tomcat
server.port = 8091
server.address = 0.0.0.0
The Error I am facing on application bootup i.e. while registering service with the consul
2:25 - Unknown error occured.
java.lang.IllegalArgumentException: service.port has not been set
at org.springframework.util.Assert.notNull(Assert.java:198)
at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.getRegistration(ConsulAutoServiceRegistration.java:56)
at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.getRegistration(ConsulAutoServiceRegistration.java:32)
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:117)
at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration.start(ConsulAutoServiceRegistration.java:68)
at com.bmc.agent.data.refresh.manager.core.ConsulLeaderElectionHelper.checkAndGetLocalService(ConsulLeaderElectionHelper.java:201)
at com.bmc.agent.data.refresh.manager.core.ConsulLeaderElectionHelper.run(ConsulLeaderElectionHelper.java:152)
Your application.properties should have the following properties as well:
spring.cloud.consul.discovery.healthCheckPath=${spring.application.name}/ManagementEndPoints/health
spring.cloud.consul.discovery.healthCheckInterval=5s
spring.cloud.consul.discovery.instance-id=${spring.application.name}
spring.cloud.consul.discovery.scheme=http or https
spring.cloud.consul.discovery.hostname=${spring.application.name}
spring.cloud.consul.discovery.port=${server.port}

How can I get Spring managed beans working with Jersey JUnit Tests?

The following isn't working:
#Override
protected Application configure() {
return new ResourceConfig(MySpringConfigBean.class).
register(org.glassfish.jersey.server.spring.SpringComponentProvider.class);
}
I have a Spring config bean that defines a Jersey REST provider bean plus other supporting beans. How do I get this working?
This is with Jersey 2.4.1

Resources