Skip to content

Configuration properties enabled in a child context are ignored if an ancestor context has already enabled the properties #41487

Closed
@miladamery

Description

@miladamery

Hi,
We have setup a spring boot application with context hierarchy according to this baeldung article. github
Given code was pretty simple but expectation is that we can configure each context management.server.port in its own .properties file. but in action only management.server.port is being read only from parent .properties file. (article doesnt have one but in our app we gave a .properties for parent too). hence when one of contexts e.g. Ctx1 gets started and gets running on port for example 9090 (when we define a separate port for actuator) and management 9095 second context (Ctx2) runs on a separate web port e.g 9091 but management port is being set to 9095 for second context too.
Or if we do not set any port in parent .properties file we get bellow error:

Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties.getPort()" is null

In ManagementWebServerFactoryCustomizer we have:

@Override
public final void customize(T factory) {
		ManagementServerProperties managementServerProperties = BeanFactoryUtils
			.beanOfTypeIncludingAncestors(this.beanFactory, ManagementServerProperties.class);
		// Customize as per the parent context first (so e.g. the access logs go to
		// the same place)
		customizeSameAsParentContext(factory);
		// Then reset the error pages
		factory.setErrorPages(Collections.emptySet());
		// and add the management-specific bits
		ServerProperties serverProperties = BeanFactoryUtils.beanOfTypeIncludingAncestors(this.beanFactory,
				ServerProperties.class);
		customize(factory, managementServerProperties, serverProperties);
}

managementServerProperties reads from parent context (in case we didnt set and is null) and actual port is set in .properties file of child context, applies to serverProperties. here is customize

protected void customize(T factory, ManagementServerProperties managementServerProperties,
			ServerProperties serverProperties) {
		factory.setPort(managementServerProperties.getPort());
		Ssl ssl = managementServerProperties.getSsl();
		if (ssl != null) {
			factory.setSsl(ssl);
		}
		factory.setServerHeader(serverProperties.getServerHeader());
		factory.setAddress(managementServerProperties.getAddress());
	}

In here factory.setPort is being set only from managementServerProperties which in this case is null and actual port is set in serverProperties. and we get the

Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties.getPort()" is null

error

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions