diff --git a/spring-boot-autoconfigure/pom.xml b/spring-boot-autoconfigure/pom.xml index fc45fad4fb..22b8d1f14a 100644 --- a/spring-boot-autoconfigure/pom.xml +++ b/spring-boot-autoconfigure/pom.xml @@ -139,6 +139,7 @@ org.apache.geronimo.specs geronimo-jms_1.1_spec + true diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/AbstractRepositoryConfigurationSourceSupport.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/AbstractRepositoryConfigurationSourceSupport.java index 1181977d37..17d77b0d71 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/AbstractRepositoryConfigurationSourceSupport.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/AbstractRepositoryConfigurationSourceSupport.java @@ -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> repositoryConfigurations = extension .getRepositoryConfigurations(configurationSource, resourceLoader); - for (final RepositoryConfiguration repositoryConfiguration : repositoryConfigurations) { + for (RepositoryConfiguration 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 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 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 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; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigureRegistrar.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigureRegistrar.java index 6ed9c1da50..4512a604cf 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigureRegistrar.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigureRegistrar.java @@ -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 getAnnotation() { + return EnableJpaRepositories.class; + } + + @Override + protected Class getConfiguration() { + return EnableJpaRepositoriesConfiguration.class; } @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/MongoRepositoriesAutoConfigureRegistrar.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/MongoRepositoriesAutoConfigureRegistrar.java index 0edd0d186a..28713bea28 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/MongoRepositoriesAutoConfigureRegistrar.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/MongoRepositoriesAutoConfigureRegistrar.java @@ -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 getAnnotation() { + return EnableMongoRepositories.class; + } + + @Override + protected Class getConfiguration() { + return EnableMongoRepositoriesConfiguration.class; } @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfiguration.java index bb08f175b2..545201ca57 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfiguration.java @@ -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"); } + } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java index 840761d873..c8c44df97b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java @@ -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; } } - } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/JdbcCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/JdbcCompilerAutoConfiguration.java index 4ad44195f7..e86442585c 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/JdbcCompilerAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/JdbcCompilerAutoConfiguration.java @@ -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", diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java index 09b7ab3cb3..7953134d99 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringMvcCompilerAutoConfiguration.java @@ -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", diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/TransactionManagementCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/TransactionManagementCompilerAutoConfiguration.java index 610f31cbca..b14f15cf40 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/TransactionManagementCompilerAutoConfiguration.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/TransactionManagementCompilerAutoConfiguration.java @@ -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", diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java index 28d38b66fc..571bea3b23 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java @@ -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. * diff --git a/spring-boot-cli/src/test/resources/logback.xml b/spring-boot-cli/src/test/resources/logback.xml index 29a2b9b369..566ec197ec 100644 --- a/spring-boot-cli/src/test/resources/logback.xml +++ b/spring-boot-cli/src/test/resources/logback.xml @@ -1,5 +1,7 @@ - + + + diff --git a/spring-boot-samples/spring-boot-sample-aop/src/main/java/org/springframework/boot/sample/aop/monitor/ServiceMonitor.java b/spring-boot-samples/spring-boot-sample-aop/src/main/java/org/springframework/boot/sample/aop/monitor/ServiceMonitor.java index 90e3a047f4..7c5efa73fb 100644 --- a/spring-boot-samples/spring-boot-sample-aop/src/main/java/org/springframework/boot/sample/aop/monitor/ServiceMonitor.java +++ b/spring-boot-samples/spring-boot-sample-aop/src/main/java/org/springframework/boot/sample/aop/monitor/ServiceMonitor.java @@ -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; diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/org/springframework/boot/sample/data/mongo/Customer.java b/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/org/springframework/boot/sample/data/mongo/Customer.java index f7e2cfe80e..1964fc3cbd 100644 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/org/springframework/boot/sample/data/mongo/Customer.java +++ b/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/org/springframework/boot/sample/data/mongo/Customer.java @@ -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 diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/org/springframework/boot/sample/data/mongo/CustomerRepository.java b/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/org/springframework/boot/sample/data/mongo/CustomerRepository.java index 2a6b2dfba3..c6bb4a5e09 100644 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/org/springframework/boot/sample/data/mongo/CustomerRepository.java +++ b/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/org/springframework/boot/sample/data/mongo/CustomerRepository.java @@ -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 { public Customer findByFirstName(String firstName); + public List findByLastName(String lastName); }