Merge branch '1.1.x'

pull/1779/head
Phillip Webb 10 years ago
commit 6cdd27a34d

@ -26,7 +26,6 @@ import org.springframework.boot.context.properties.ConfigurationBeanFactoryMetaD
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.util.StringUtils;
@ -116,9 +115,8 @@ public class ConfigurationPropertiesReportEndpoint extends
for (Map.Entry<String, Object> entry : beans.entrySet()) {
String beanName = entry.getKey();
Object bean = entry.getValue();
Map<String, Object> root = new HashMap<String, Object>();
root.put("prefix", extractPrefix(beanName, bean));
root.put("prefix", extractPrefix(context, beanName, bean));
root.put("properties", sanitize(mapper.convertValue(bean, Map.class)));
result.put(beanName, root);
}
@ -162,9 +160,9 @@ public class ConfigurationPropertiesReportEndpoint extends
/**
* Extract configuration prefix from {@link ConfigurationProperties} annotation.
*/
private String extractPrefix(String beanName, Object bean) {
ConfigurationProperties annotation = AnnotationUtils.findAnnotation(
bean.getClass(), ConfigurationProperties.class);
private String extractPrefix(ApplicationContext context, String beanName, Object bean) {
ConfigurationProperties annotation = context.findAnnotationOnBean(beanName,
ConfigurationProperties.class);
if (this.beanFactoryMetaData != null) {
ConfigurationProperties override = this.beanFactoryMetaData
.findFactoryAnnotation(beanName, ConfigurationProperties.class);

@ -0,0 +1,122 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.endpoint;
import java.util.Map;
import javax.sql.DataSource;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.context.properties.ConfigurationBeanFactoryMetaData;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link ConfigurationPropertiesReportEndpoint} when used against a proxy
* class.
*
* @author Phillip Webb
*/
public class ConfigurationPropertiesReportEndpointProxyTests {
private AnnotationConfigApplicationContext context;
@Before
public void setup() {
this.context = new AnnotationConfigApplicationContext();
}
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void testWithProxyClass() throws Exception {
this.context.register(Config.class, SqlExecutor.class);
this.context.refresh();
Map<String, Object> report = this.context.getBean(
ConfigurationPropertiesReportEndpoint.class).invoke();
assertThat(report.toString(), containsString("prefix=executor.sql"));
}
@Configuration
@EnableTransactionManagement(proxyTargetClass = false)
@EnableConfigurationProperties
public static class Config {
@Bean
public ConfigurationPropertiesReportEndpoint endpoint(
ConfigurationBeanFactoryMetaData beanFactoryMetaData) {
ConfigurationPropertiesReportEndpoint endpoint = new ConfigurationPropertiesReportEndpoint();
endpoint.setConfigurationBeanFactoryMetaData(beanFactoryMetaData);
return endpoint;
}
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.build();
}
}
public static interface Executor {
public void execute();
}
public static abstract class AbstractExecutor implements Executor {
}
@Component
@ConfigurationProperties("executor.sql")
public static class SqlExecutor extends AbstractExecutor {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void execute() {
}
}
}
Loading…
Cancel
Save