Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoimport defined in lib won't be used #35851

Closed
askingcat opened this issue Jun 12, 2023 · 4 comments
Closed

autoimport defined in lib won't be used #35851

askingcat opened this issue Jun 12, 2023 · 4 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@askingcat
Copy link

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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 12, 2023
@snicoll
Copy link
Member

snicoll commented Jun 12, 2023

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.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Jun 12, 2023
@askingcat
Copy link
Author

"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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 12, 2023
@snicoll
Copy link
Member

snicoll commented Jun 12, 2023

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.

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jun 12, 2023
@askingcat
Copy link
Author

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.

@askingcat askingcat reopened this Jun 12, 2023
@scottfrederick scottfrederick closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2023
@scottfrederick scottfrederick added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants