mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
This commit is contained in:
parent
d07e18143d
commit
fbf34e261e
@ -32,11 +32,24 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ManagedResource
|
||||
public class DataEndpointMBean extends EndpointMBean {
|
||||
|
||||
/**
|
||||
* Create a new {@link DataEndpointMBean} instance.
|
||||
* @param beanName the bean name
|
||||
* @param endpoint the endpoint to wrap
|
||||
* @deprecated since 1.3 in favor of
|
||||
* {@link #DataEndpointMBean(String, Endpoint, ObjectMapper)}
|
||||
*/
|
||||
@Deprecated
|
||||
public DataEndpointMBean(String beanName, Endpoint<?> endpoint) {
|
||||
super(beanName, endpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link DataEndpointMBean} instance.
|
||||
* @param beanName the bean name
|
||||
* @param endpoint the endpoint to wrap
|
||||
* @param objectMapper the {@link ObjectMapper} used to convert the payload
|
||||
*/
|
||||
public DataEndpointMBean(String beanName, Endpoint<?> endpoint,
|
||||
ObjectMapper objectMapper) {
|
||||
super(beanName, endpoint, objectMapper);
|
||||
|
@ -40,11 +40,24 @@ public class EndpointMBean {
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
/**
|
||||
* Create a new {@link EndpointMBean} instance.
|
||||
* @param beanName the bean name
|
||||
* @param endpoint the endpoint to wrap
|
||||
* @deprecated since 1.3 in favor of
|
||||
* {@link #EndpointMBean(String, Endpoint, ObjectMapper)}
|
||||
*/
|
||||
@Deprecated
|
||||
public EndpointMBean(String beanName, Endpoint<?> endpoint) {
|
||||
this(beanName, endpoint, new ObjectMapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link EndpointMBean} instance.
|
||||
* @param beanName the bean name
|
||||
* @param endpoint the endpoint to wrap
|
||||
* @param objectMapper the {@link ObjectMapper} used to convert the payload
|
||||
*/
|
||||
public EndpointMBean(String beanName, Endpoint<?> endpoint, ObjectMapper objectMapper) {
|
||||
Assert.notNull(beanName, "BeanName must not be null");
|
||||
Assert.notNull(endpoint, "Endpoint must not be null");
|
||||
@ -71,15 +84,12 @@ public class EndpointMBean {
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (result instanceof String) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (result.getClass().isArray() || result instanceof List) {
|
||||
return this.mapper.convertValue(result, List.class);
|
||||
}
|
||||
|
||||
return this.mapper.convertValue(result, Map.class);
|
||||
}
|
||||
|
||||
|
@ -96,12 +96,19 @@ public class EndpointMBeanExporter extends MBeanExporter implements SmartLifecyc
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* Create a new {@link EndpointMBeanExporter} instance.
|
||||
*/
|
||||
public EndpointMBeanExporter() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link EndpointMBeanExporter} instance.
|
||||
* @param objectMapper the object mapper
|
||||
*/
|
||||
public EndpointMBeanExporter(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper == null ? new ObjectMapper() : objectMapper;
|
||||
this.objectMapper = (objectMapper == null ? new ObjectMapper() : objectMapper);
|
||||
setAutodetect(false);
|
||||
setNamingStrategy(this.defaultNamingStrategy);
|
||||
setAssembler(this.assembler);
|
||||
|
@ -32,14 +32,27 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ManagedResource
|
||||
public class ShutdownEndpointMBean extends EndpointMBean {
|
||||
|
||||
/**
|
||||
* Create a new {@link ShutdownEndpointMBean} instance.
|
||||
* @param beanName the bean name
|
||||
* @param endpoint the endpoint to wrap
|
||||
* @deprecated since 1.3 in favor of
|
||||
* {@link #ShutdownEndpointMBean(String, Endpoint, ObjectMapper)}
|
||||
*/
|
||||
@Deprecated
|
||||
public ShutdownEndpointMBean(String beanName, Endpoint<?> endpoint) {
|
||||
super(beanName, endpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ShutdownEndpointMBean} instance.
|
||||
* @param beanName the bean name
|
||||
* @param endpoint the endpoint to wrap
|
||||
* @param objectMapper the {@link ObjectMapper} used to convert the payload
|
||||
*/
|
||||
public ShutdownEndpointMBean(String beanName, Endpoint<?> endpoint,
|
||||
ObjectMapper mapper) {
|
||||
super(beanName, endpoint, mapper);
|
||||
ObjectMapper objectMapper) {
|
||||
super(beanName, endpoint, objectMapper);
|
||||
}
|
||||
|
||||
@ManagedOperation(description = "Shutdown the ApplicationContext")
|
||||
|
@ -73,9 +73,7 @@ public class EndpointMBeanExporterTests {
|
||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||
TestEndpoint.class));
|
||||
this.context.refresh();
|
||||
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
|
||||
MBeanInfo mbeanInfo = mbeanExporter.getServer().getMBeanInfo(
|
||||
getObjectName("endpoint1", this.context));
|
||||
assertNotNull(mbeanInfo);
|
||||
@ -93,9 +91,7 @@ public class EndpointMBeanExporterTests {
|
||||
this.context.registerBeanDefinition("endpoint2", new RootBeanDefinition(
|
||||
TestEndpoint.class));
|
||||
this.context.refresh();
|
||||
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
|
||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||
getObjectName("endpoint1", this.context)));
|
||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||
@ -113,9 +109,7 @@ public class EndpointMBeanExporterTests {
|
||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||
TestEndpoint.class));
|
||||
this.context.refresh();
|
||||
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
|
||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||
getObjectName("test-domain", "endpoint1", false, this.context)));
|
||||
}
|
||||
@ -132,9 +126,7 @@ public class EndpointMBeanExporterTests {
|
||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||
TestEndpoint.class));
|
||||
this.context.refresh();
|
||||
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
|
||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||
getObjectName("test-domain", "endpoint1", true, this.context)));
|
||||
}
|
||||
@ -156,9 +148,7 @@ public class EndpointMBeanExporterTests {
|
||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||
TestEndpoint.class));
|
||||
this.context.refresh();
|
||||
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
|
||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||
ObjectNameManager.getInstance(getObjectName("test-domain", "endpoint1",
|
||||
true, this.context).toString()
|
||||
@ -173,13 +163,10 @@ public class EndpointMBeanExporterTests {
|
||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||
TestEndpoint.class));
|
||||
GenericApplicationContext parent = new GenericApplicationContext();
|
||||
|
||||
this.context.setParent(parent);
|
||||
parent.refresh();
|
||||
this.context.refresh();
|
||||
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
|
||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||
getObjectName("endpoint1", this.context)));
|
||||
|
||||
@ -194,12 +181,10 @@ public class EndpointMBeanExporterTests {
|
||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||
JsonConversionEndpoint.class));
|
||||
this.context.refresh();
|
||||
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
Object response = mbeanExporter.getServer().invoke(
|
||||
getObjectName("endpoint1", this.context), "getData", new Object[0],
|
||||
new String[0]);
|
||||
|
||||
assertThat(response, is(instanceOf(Map.class)));
|
||||
assertThat(((Map<?, ?>) response).get("date"), is(instanceOf(Long.class)));
|
||||
}
|
||||
@ -217,12 +202,10 @@ public class EndpointMBeanExporterTests {
|
||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||
JsonConversionEndpoint.class));
|
||||
this.context.refresh();
|
||||
|
||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||
Object response = mbeanExporter.getServer().invoke(
|
||||
getObjectName("endpoint1", this.context), "getData", new Object[0],
|
||||
new String[0]);
|
||||
|
||||
assertThat(response, is(instanceOf(Map.class)));
|
||||
assertThat(((Map<?, ?>) response).get("date"), is(instanceOf(String.class)));
|
||||
}
|
||||
@ -242,10 +225,8 @@ public class EndpointMBeanExporterTests {
|
||||
.getIdentityHexString(applicationContext
|
||||
.getBean(beanKey))));
|
||||
}
|
||||
else {
|
||||
return ObjectNameManager.getInstance(String.format(
|
||||
"%s:type=Endpoint,name=%s", domain, beanKey));
|
||||
}
|
||||
return ObjectNameManager.getInstance(String.format("%s:type=Endpoint,name=%s",
|
||||
domain, beanKey));
|
||||
}
|
||||
|
||||
public static class TestEndpoint extends AbstractEndpoint<String> {
|
||||
@ -258,6 +239,7 @@ public class EndpointMBeanExporterTests {
|
||||
public String invoke() {
|
||||
return "hello world";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class JsonConversionEndpoint extends
|
||||
|
@ -73,8 +73,7 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector,
|
||||
this.beanClassLoader)));
|
||||
|
||||
// Remove those specifically disabled
|
||||
List<String> excluded = new ArrayList<String>(Arrays.asList(attributes
|
||||
.getStringArray("exclude")));
|
||||
List<String> excluded = Arrays.asList(attributes.getStringArray("exclude"));
|
||||
factories.removeAll(excluded);
|
||||
ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded);
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.condition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
@ -87,7 +88,7 @@ public class ConditionEvaluationReport {
|
||||
*/
|
||||
public void recordExclusions(List<String> exclusions) {
|
||||
Assert.notNull(exclusions, "exclusions must not be null");
|
||||
this.exclusions = exclusions;
|
||||
this.exclusions = new ArrayList<String>(exclusions);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,14 +107,6 @@ public class ConditionEvaluationReport {
|
||||
return Collections.unmodifiableMap(this.outcomes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the classes that have been excluded from condition evaluation.
|
||||
* @return the names of the excluded classes
|
||||
*/
|
||||
public List<String> getExclusions() {
|
||||
return Collections.unmodifiableList(this.exclusions);
|
||||
}
|
||||
|
||||
private void addNoMatchOutcomeToAncestors(String source) {
|
||||
String prefix = source + "$";
|
||||
for (Entry<String, ConditionAndOutcomes> entry : this.outcomes.entrySet()) {
|
||||
@ -125,6 +118,14 @@ public class ConditionEvaluationReport {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the classes that have been excluded from condition evaluation.
|
||||
* @return the names of the excluded classes
|
||||
*/
|
||||
public List<String> getExclusions() {
|
||||
return Collections.unmodifiableList(this.exclusions);
|
||||
}
|
||||
|
||||
/**
|
||||
* The parent report (from a parent BeanFactory if there is one).
|
||||
* @return the parent report (or null if there isn't one)
|
||||
|
Loading…
Reference in New Issue
Block a user