Skip to content

Commit fcdc414

Browse files
committed
Remove use of @Autowired for configuration properties bean
See gh-8762
1 parent c4b8328 commit fcdc414

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/DefaultEndpointObjectNameFactory.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class DefaultEndpointObjectNameFactory implements EndpointObjectNameFactory {
3737

3838
private final JmxEndpointProperties properties;
3939

40+
private final Environment environment;
41+
4042
private final MBeanServer mBeanServer;
4143

4244
private final String contextId;
@@ -46,6 +48,7 @@ class DefaultEndpointObjectNameFactory implements EndpointObjectNameFactory {
4648
DefaultEndpointObjectNameFactory(JmxEndpointProperties properties,
4749
Environment environment, MBeanServer mBeanServer, String contextId) {
4850
this.properties = properties;
51+
this.environment = environment;
4952
this.mBeanServer = mBeanServer;
5053
this.contextId = contextId;
5154
this.uniqueNames = environment.getProperty("spring.jmx.unique-names",
@@ -55,7 +58,7 @@ class DefaultEndpointObjectNameFactory implements EndpointObjectNameFactory {
5558
@Override
5659
public ObjectName getObjectName(ExposableJmxEndpoint endpoint)
5760
throws MalformedObjectNameException {
58-
StringBuilder builder = new StringBuilder(this.properties.getDomain());
61+
StringBuilder builder = new StringBuilder(determineDomain());
5962
builder.append(":type=Endpoint");
6063
builder.append(",name=")
6164
.append(StringUtils.capitalize(endpoint.getEndpointId().toString()));
@@ -71,6 +74,14 @@ public ObjectName getObjectName(ExposableJmxEndpoint endpoint)
7174
return ObjectNameManager.getInstance(builder.toString());
7275
}
7376

77+
private String determineDomain() {
78+
if (StringUtils.hasText(this.properties.getDomain())) {
79+
return this.properties.getDomain();
80+
}
81+
return this.environment.getProperty("spring.jmx.default-domain",
82+
"org.springframework.boot");
83+
}
84+
7485
private boolean hasMBean(String baseObjectName) throws MalformedObjectNameException {
7586
ObjectName query = new ObjectName(baseObjectName + ",*");
7687
return !this.mBeanServer.queryNames(query, null).isEmpty();

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointProperties.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
import java.util.Properties;
2121
import java.util.Set;
2222

23-
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.boot.context.properties.ConfigurationProperties;
25-
import org.springframework.core.env.Environment;
26-
import org.springframework.util.StringUtils;
2724

2825
/**
2926
* Configuration properties for JMX export of endpoints.
@@ -39,22 +36,14 @@ public class JmxEndpointProperties {
3936
/**
4037
* Endpoints JMX domain name. Fallback to 'spring.jmx.default-domain' if set.
4138
*/
42-
private String domain = "org.springframework.boot";
39+
private String domain;
4340

4441
/**
4542
* Additional static properties to append to all ObjectNames of MBeans representing
4643
* Endpoints.
4744
*/
4845
private final Properties staticNames = new Properties();
4946

50-
@Autowired
51-
public JmxEndpointProperties(Environment environment) {
52-
String defaultDomain = environment.getProperty("spring.jmx.default-domain");
53-
if (StringUtils.hasText(defaultDomain)) {
54-
this.domain = defaultDomain;
55-
}
56-
}
57-
5847
public Exposure getExposure() {
5948
return this.exposure;
6049
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
"type": "java.lang.Boolean",
3434
"description": "Whether to enable or disable all endpoints by default."
3535
},
36+
{
37+
"name": "management.endpoints.jmx.domain",
38+
"defaultValue": "org.springframework.boot"
39+
},
3640
{
3741
"name": "management.endpoints.jmx.exposure.include",
3842
"defaultValue": "*"

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public class SessionProperties {
5757

5858
private Servlet servlet = new Servlet();
5959

60-
private final ServerProperties serverProperties;
60+
private ServerProperties serverProperties;
6161

6262
@Autowired
63-
public SessionProperties(ObjectProvider<ServerProperties> serverProperties) {
63+
void setServerProperties(ObjectProvider<ServerProperties> serverProperties) {
6464
this.serverProperties = serverProperties.getIfUnique();
6565
}
6666

0 commit comments

Comments
 (0)