In a current project I have a library defining an autoimport via org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports (until recently spring.factories was used). In the main service importing this library the autoimport won't be loaded automatically. If I add the same file to the main service, the loading will work without a problem.
Used Spring Boot version: 3.1.0
Potentially related: #32222
Example code for the lib:
package com.foo.mvc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet.WebMvcEndpointManagementContextConfiguration;
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
import org.springframework.core.env.Environment;
public class ActuatorConfig extends WebMvcEndpointManagementContextConfiguration {
private static final Logger log = LoggerFactory.getLogger(ActuatorConfig.class);
@Override
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties,
WebEndpointProperties webEndpointProperties, Environment environment
) {
var mapping = super.webEndpointServletHandlerMapping(
webEndpointsSupplier, servletEndpointsSupplier, controllerEndpointsSupplier, endpointMediaTypes, corsProperties,
webEndpointProperties,
environment
);
log.info("actuator configuration loaded");
return mapping;
}
}
Autoimport file at src/main/resources/META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports
com.foo.mvc.ActuatorConfig
Comment From: snicoll
I am not sure what you mean by "autoimport". These are supposed to be auto-configurations, with a well defined lifecycle. Looking at your class, it looks like it's trying to contribute a bean directly which looks a bit odd.
That said, if it used to work, we should be able to give you some pointers or fix a bug. Can you please share a small sample that works when the file is added in the app but does not when it is added to the lib. You can share the sample as a zip attached to this issue or by pushing it to a GitHub repo.
Comment From: askingcat
"autoimport" might not be the correct terminology - sorry for the confusion.
I was referring to the auto-configuration changed originally with Spring 2.7. With Spring 3.0 the spring.factories, which have been formerly used, have now been removed.
In my use case we want to modify the behavior of the actuator endpoints, which are not configured by the org.springframework.boot.autoconfigure.AutoConfiguration.imports - since this just defines the default application context - but seem to be governed by org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports instead.
The implementation is currently based on this discussion, since in our context a Filter would not work, since we require the context of the interceptor.
Comment From: snicoll
Yes, I am aware of what the change is but autoimport is still confusing here. As I've asked before, please share a small sample we can run ourselves.
Comment From: askingcat
After some hours of debugging it turned out that apparently a cached snapshot variant (by gradle) somewhere in the dependency tree seems to have been responsible for the problem, although I couldn't track it down anymore.
I noticed this when I created a minimal example with Maven and was getting different results. Unfortunately after trying to narrow the dependency problem with the gradle-based service it eventually started also working and I assume during the build changes I forced an update for an unknown dependency.
Sorry for the unnecessary overhead for you @snicoll.