Skip to content

Commit 6f68b03

Browse files
committed
MBeanExportConfiguration's SpecificPlatform properly calls afterPropertiesSet
Also makes the nested SpecificPlatform enum public for Spring Boot to reuse it. Issue: SPR-11877
1 parent ab5aea5 commit 6f68b03

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,19 +18,20 @@
1818

1919
import java.util.Map;
2020
import javax.management.MBeanServer;
21+
import javax.naming.NamingException;
2122

2223
import org.springframework.beans.factory.BeanFactory;
2324
import org.springframework.beans.factory.BeanFactoryAware;
24-
import org.springframework.beans.factory.FactoryBean;
2525
import org.springframework.beans.factory.config.BeanDefinition;
2626
import org.springframework.context.EnvironmentAware;
2727
import org.springframework.core.annotation.AnnotationAttributes;
2828
import org.springframework.core.env.Environment;
2929
import org.springframework.core.type.AnnotationMetadata;
30+
import org.springframework.jmx.MBeanServerNotFoundException;
3031
import org.springframework.jmx.export.annotation.AnnotationMBeanExporter;
3132
import org.springframework.jmx.support.RegistrationPolicy;
3233
import org.springframework.jmx.support.WebSphereMBeanServerFactoryBean;
33-
import org.springframework.jndi.JndiObjectFactoryBean;
34+
import org.springframework.jndi.JndiLocatorDelegate;
3435
import org.springframework.util.Assert;
3536
import org.springframework.util.ClassUtils;
3637
import org.springframework.util.StringUtils;
@@ -119,21 +120,26 @@ private void setupRegistrationPolicy(AnnotationMBeanExporter exporter) {
119120
}
120121

121122

122-
private static enum SpecificPlatform {
123+
public static enum SpecificPlatform {
123124

124125
WEBLOGIC("weblogic.management.Helper") {
125126
@Override
126-
public FactoryBean<?> getMBeanServerFactory() {
127-
JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
128-
factory.setJndiName("java:comp/env/jmx/runtime");
129-
return factory;
127+
public MBeanServer getMBeanServer() {
128+
try {
129+
return new JndiLocatorDelegate().lookup("java:comp/env/jmx/runtime", MBeanServer.class);
130+
}
131+
catch (NamingException ex) {
132+
throw new MBeanServerNotFoundException("Failed to retrieve WebLogic MBeanServer from JNDI", ex);
133+
}
130134
}
131135
},
132136

133137
WEBSPHERE("com.ibm.websphere.management.AdminServiceFactory") {
134138
@Override
135-
public FactoryBean<MBeanServer> getMBeanServerFactory() {
136-
return new WebSphereMBeanServerFactoryBean();
139+
public MBeanServer getMBeanServer() {
140+
WebSphereMBeanServerFactoryBean fb = new WebSphereMBeanServerFactoryBean();
141+
fb.afterPropertiesSet();
142+
return fb.getObject();
137143
}
138144
};
139145

@@ -143,19 +149,7 @@ private SpecificPlatform(String identifyingClass) {
143149
this.identifyingClass = identifyingClass;
144150
}
145151

146-
public MBeanServer getMBeanServer() {
147-
Object server;
148-
try {
149-
server = getMBeanServerFactory().getObject();
150-
Assert.isInstanceOf(MBeanServer.class, server);
151-
return (MBeanServer) server;
152-
}
153-
catch (Exception ex) {
154-
throw new IllegalStateException(ex);
155-
}
156-
}
157-
158-
protected abstract FactoryBean<?> getMBeanServerFactory();
152+
public abstract MBeanServer getMBeanServer();
159153

160154
public static SpecificPlatform get() {
161155
ClassLoader classLoader = MBeanExportConfiguration.class.getClassLoader();

0 commit comments

Comments
 (0)