pull/51/merge
Phillip Webb 11 years ago
parent b857a9001d
commit 9a529b41c1

@ -139,6 +139,7 @@
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<optional>true</optional>
</dependency>
<!-- Test -->
<dependency>

@ -41,34 +41,38 @@ import org.springframework.data.repository.config.RepositoryConfiguration;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
/**
* Base {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data
* Repositories.
*
* @author Phillip Webb
* @author Dave Syer
*/
public abstract class AbstractRepositoryConfigurationSourceSupport implements
BeanFactoryAware, ImportBeanDefinitionRegistrar, BeanClassLoaderAware {
private ClassLoader beanClassLoader;
private static Log logger = LogFactory
.getLog(AbstractRepositoryConfigurationSourceSupport.class);
private ClassLoader beanClassLoader;
private BeanFactory beanFactory;
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
final BeanDefinitionRegistry registry) {
final ResourceLoader resourceLoader = new DefaultResourceLoader();
final AnnotationRepositoryConfigurationSource configurationSource = getConfigurationSource();
final RepositoryConfigurationExtension extension = getRepositoryConfigurationExtension();
ResourceLoader resourceLoader = new DefaultResourceLoader();
AnnotationRepositoryConfigurationSource configurationSource = getConfigurationSource();
RepositoryConfigurationExtension extension = getRepositoryConfigurationExtension();
extension.registerBeansForRoot(registry, configurationSource);
final RepositoryBeanNameGenerator generator = new RepositoryBeanNameGenerator();
RepositoryBeanNameGenerator generator = new RepositoryBeanNameGenerator();
generator.setBeanClassLoader(this.beanClassLoader);
Collection<RepositoryConfiguration<AnnotationRepositoryConfigurationSource>> repositoryConfigurations = extension
.getRepositoryConfigurations(configurationSource, resourceLoader);
for (final RepositoryConfiguration<AnnotationRepositoryConfigurationSource> repositoryConfiguration : repositoryConfigurations) {
for (RepositoryConfiguration<AnnotationRepositoryConfigurationSource> repositoryConfiguration : repositoryConfigurations) {
RepositoryBeanDefinitionBuilder builder = new RepositoryBeanDefinitionBuilder(
repositoryConfiguration, extension);
BeanDefinitionBuilder definitionBuilder = builder.build(registry,
@ -82,21 +86,11 @@ public abstract class AbstractRepositoryConfigurationSourceSupport implements
}
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
protected abstract RepositoryConfigurationExtension getRepositoryConfigurationExtension();
protected abstract AnnotationRepositoryConfigurationSource getConfigurationSource();
protected AnnotationRepositoryConfigurationSource getConfigurationSource(
Class<?> annotated, Class<? extends Annotation> annotation) {
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(annotated,
true);
private AnnotationRepositoryConfigurationSource getConfigurationSource() {
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(
getConfiguration(), true);
AnnotationRepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(
metadata, annotation) {
metadata, getAnnotation()) {
@Override
public java.lang.Iterable<String> getBasePackages() {
@ -117,6 +111,26 @@ public abstract class AbstractRepositoryConfigurationSourceSupport implements
return basePackages;
}
/**
* The Spring Data annotation used to enable the particular repository support.
*/
protected abstract Class<? extends Annotation> getAnnotation();
/**
* The configuration class that will be used by Spring Boot as a template.
*/
protected abstract Class<?> getConfiguration();
/**
* The {@link RepositoryConfigurationExtension} for the particular repository support.
*/
protected abstract RepositoryConfigurationExtension getRepositoryConfigurationExtension();
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;

@ -16,10 +16,11 @@
package org.springframework.boot.autoconfigure.data;
import java.lang.annotation.Annotation;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
/**
@ -33,9 +34,13 @@ class JpaRepositoriesAutoConfigureRegistrar extends
AbstractRepositoryConfigurationSourceSupport {
@Override
protected AnnotationRepositoryConfigurationSource getConfigurationSource() {
return getConfigurationSource(EnableJpaRepositoriesConfiguration.class,
EnableJpaRepositories.class);
protected Class<? extends Annotation> getAnnotation() {
return EnableJpaRepositories.class;
}
@Override
protected Class<?> getConfiguration() {
return EnableJpaRepositoriesConfiguration.class;
}
@Override

@ -16,10 +16,11 @@
package org.springframework.boot.autoconfigure.data;
import java.lang.annotation.Annotation;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.data.mongodb.repository.config.MongoRepositoryConfigurationExtension;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
/**
@ -32,9 +33,13 @@ class MongoRepositoriesAutoConfigureRegistrar extends
AbstractRepositoryConfigurationSourceSupport {
@Override
protected AnnotationRepositoryConfigurationSource getConfigurationSource() {
return getConfigurationSource(EnableMongoRepositoriesConfiguration.class,
EnableMongoRepositories.class);
protected Class<? extends Annotation> getAnnotation() {
return EnableMongoRepositories.class;
}
@Override
protected Class<?> getConfiguration() {
return EnableMongoRepositoriesConfiguration.class;
}
@Override

@ -41,11 +41,11 @@ public class JmsTemplateAutoConfiguration {
protected static class JmsTemplateCreator {
@Autowired
ConnectionFactory connectionFactory;
private ConnectionFactory connectionFactory;
@Bean
public JmsTemplate jmsTemplate() {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
JmsTemplate jmsTemplate = new JmsTemplate(this.connectionFactory);
jmsTemplate.setPubSubDomain(true);
return jmsTemplate;
}
@ -56,10 +56,12 @@ public class JmsTemplateAutoConfiguration {
@ConditionalOnClass(ActiveMQConnectionFactory.class)
@ConditionalOnMissingBean(ConnectionFactory.class)
protected static class ActiveMQConnectionFactoryCreator {
@Bean
ConnectionFactory connectionFactory() {
return new ActiveMQConnectionFactory("vm://localhost");
}
}
}

@ -16,11 +16,6 @@
package org.springframework.boot.autoconfigure.jms;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
@ -32,6 +27,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.core.JmsTemplate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link JmsTemplateAutoConfiguration}.
*
@ -55,10 +55,6 @@ public class JmsTemplateAutoConfigurationTests {
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
}
@Configuration
protected static class TestConfiguration {
}
@Test
public void testConnectionFactoryBackoff() {
this.context = new AnnotationConfigApplicationContext();
@ -69,18 +65,6 @@ public class JmsTemplateAutoConfigurationTests {
.getBrokerURL());
}
@Configuration
protected static class TestConfiguration2 {
@Bean
ConnectionFactory connectionFactory() {
return new ActiveMQConnectionFactory() {
{
setBrokerURL("foobar");
}
};
}
}
@Test
public void testJmsTemplateBackoff() {
this.context = new AnnotationConfigApplicationContext();
@ -91,17 +75,6 @@ public class JmsTemplateAutoConfigurationTests {
assertEquals(999, jmsTemplate.getPriority());
}
@Configuration
protected static class TestConfiguration3 {
@Bean
JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.setPriority(999);
return jmsTemplate;
}
}
@Test
public void testJmsTemplateBackoffEverything() {
this.context = new AnnotationConfigApplicationContext();
@ -134,6 +107,33 @@ public class JmsTemplateAutoConfigurationTests {
assertFalse(jmsTemplate.isPubSubDomain());
}
@Configuration
protected static class TestConfiguration {
}
@Configuration
protected static class TestConfiguration2 {
@Bean
ConnectionFactory connectionFactory() {
return new ActiveMQConnectionFactory() {
{
setBrokerURL("foobar");
}
};
}
}
@Configuration
protected static class TestConfiguration3 {
@Bean
JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.setPriority(999);
return jmsTemplate;
}
}
@Configuration
protected static class TestConfiguration4 implements BeanPostProcessor {
@Override
@ -152,5 +152,4 @@ public class JmsTemplateAutoConfigurationTests {
return bean;
}
}
}

@ -29,6 +29,12 @@ import org.springframework.boot.cli.compiler.DependencyCustomizer;
*/
public class JdbcCompilerAutoConfiguration extends CompilerAutoConfiguration {
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneFieldOrMethod(classNode, "JdbcTemplate",
"NamedParameterJdbcTemplate", "DataSource");
}
@Override
public void applyDependencies(DependencyCustomizer dependencies) {
dependencies.ifAnyMissingClasses("org.springframework.jdbc.core.JdbcTemplate")
@ -36,12 +42,6 @@ public class JdbcCompilerAutoConfiguration extends CompilerAutoConfiguration {
dependencies.getProperty("spring-boot.version"));
}
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneFieldOrMethod(classNode, "JdbcTemplate",
"NamedParameterJdbcTemplate", "DataSource");
}
@Override
public void applyImports(ImportCustomizer imports) {
imports.addStarImports("org.springframework.jdbc.core",

@ -36,6 +36,12 @@ import org.springframework.boot.cli.compiler.DependencyCustomizer;
*/
public class SpringMvcCompilerAutoConfiguration extends CompilerAutoConfiguration {
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "Controller",
"RestController", "EnableWebMvc", "WebConfiguration");
}
@Override
public void applyDependencies(DependencyCustomizer dependencies) {
dependencies
@ -47,12 +53,6 @@ public class SpringMvcCompilerAutoConfiguration extends CompilerAutoConfiguratio
dependencies.getProperty("groovy.version"));
}
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "Controller",
"RestController", "EnableWebMvc", "WebConfiguration");
}
@Override
public void applyImports(ImportCustomizer imports) {
imports.addStarImports("org.springframework.web.bind.annotation",

@ -31,6 +31,11 @@ import org.springframework.boot.cli.compiler.DependencyCustomizer;
public class TransactionManagementCompilerAutoConfiguration extends
CompilerAutoConfiguration {
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableTransactionManagement");
}
@Override
public void applyDependencies(DependencyCustomizer dependencies) {
dependencies
@ -42,11 +47,6 @@ public class TransactionManagementCompilerAutoConfiguration extends
dependencies.getProperty("spring-boot.version"));
}
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableTransactionManagement");
}
@Override
public void applyImports(ImportCustomizer imports) {
imports.addStarImports("org.springframework.transaction.annotation",

@ -16,9 +16,6 @@
package org.springframework.boot.cli;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.net.URL;
import java.util.concurrent.Callable;
@ -36,6 +33,9 @@ import org.springframework.boot.OutputCapture;
import org.springframework.boot.cli.command.CleanCommand;
import org.springframework.boot.cli.command.RunCommand;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Integration tests to exercise the samples.
*

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<!-- logger name="org.springframework.web" level="DEBUG"/-->
<!-- logger name="org.springframework.jdbc" level="DEBUG"/-->
<!-- logger name="org.springframework.jms" level="DEBUG"/-->
</configuration>

@ -1,3 +1,19 @@
/*
* Copyright 2013 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.sample.aop.monitor;
import org.aspectj.lang.JoinPoint;

@ -1,8 +1,23 @@
/*
* Copyright 2013 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.sample.data.mongo;
import org.springframework.data.annotation.Id;
public class Customer {
@Id

@ -1,3 +1,19 @@
/*
* Copyright 2013 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.sample.data.mongo;
import java.util.List;
@ -7,6 +23,7 @@ import org.springframework.data.mongodb.repository.MongoRepository;
public interface CustomerRepository extends MongoRepository<Customer, String> {
public Customer findByFirstName(String firstName);
public List<Customer> findByLastName(String lastName);
}

Loading…
Cancel
Save