diff --git a/spring-data-mongodb-parent/pom.xml b/spring-data-mongodb-parent/pom.xml
index 2386a000f..7d08da5ee 100644
--- a/spring-data-mongodb-parent/pom.xml
+++ b/spring-data-mongodb-parent/pom.xml
@@ -18,7 +18,7 @@
3.0.7.RELEASE
4.0.0.RELEASE
[${org.springframework.version.30}, ${org.springframework.version.40})
- 1.3.2.BUILD-SNAPSHOT
+ 1.4.0.BUILD-SNAPSHOT
1.6.11.RELEASE
true
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoNamespaceHandler.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoNamespaceHandler.java
index 4eb27dee5..a01de7878 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoNamespaceHandler.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoNamespaceHandler.java
@@ -16,7 +16,9 @@
package org.springframework.data.mongodb.config;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
-import org.springframework.data.mongodb.repository.config.MongoRepositoryConfigParser;
+import org.springframework.data.mongodb.repository.config.MongoRepositoryConfigurationExtension;
+import org.springframework.data.repository.config.RepositoryBeanDefinitionParser;
+import org.springframework.data.repository.config.RepositoryConfigurationExtension;
/**
* {@link org.springframework.beans.factory.xml.NamespaceHandler} for Mongo DB based repositories.
@@ -32,7 +34,10 @@ public class MongoNamespaceHandler extends NamespaceHandlerSupport {
*/
public void init() {
- registerBeanDefinitionParser("repositories", new MongoRepositoryConfigParser());
+ RepositoryConfigurationExtension extension = new MongoRepositoryConfigurationExtension();
+ RepositoryBeanDefinitionParser repositoryBeanDefinitionParser = new RepositoryBeanDefinitionParser(extension);
+
+ registerBeanDefinitionParser("repositories", repositoryBeanDefinitionParser);
registerBeanDefinitionParser("mapping-converter", new MappingMongoConverterParser());
registerBeanDefinitionParser("mongo", new MongoParser());
registerBeanDefinitionParser("db-factory", new MongoDbFactoryParser());
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/EnableMongoRepositories.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/EnableMongoRepositories.java
new file mode 100644
index 000000000..b2ba8f648
--- /dev/null
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/EnableMongoRepositories.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2012 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.data.mongodb.repository.config;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean;
+import org.springframework.data.repository.query.QueryLookupStrategy;
+import org.springframework.data.repository.query.QueryLookupStrategy.Key;
+
+/**
+ * Annotation to activate MongoDB repositories. If no base package is configured through either {@link #value()},
+ * {@link #basePackages()} or {@link #basePackageClasses()} it will trigger scanning of the package of annotated class.
+ *
+ * @author Oliver Gierke
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Import(MongoRepositoriesRegistrar.class)
+public @interface EnableMongoRepositories {
+
+ /**
+ * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation declarations e.g.:
+ * {@code @EnableJpaRepositories("org.my.pkg")} instead of {@code @EnableJpaRepositories(basePackages="org.my.pkg")}.
+ */
+ String[] value() default {};
+
+ /**
+ * Base packages to scan for annotated components. {@link #value()} is an alias for (and mutually exclusive with) this
+ * attribute. Use {@link #basePackageClasses()} for a type-safe alternative to String-based package names.
+ */
+ String[] basePackages() default {};
+
+ /**
+ * Type-safe alternative to {@link #basePackages()} for specifying the packages to scan for annotated components. The
+ * package of each class specified will be scanned. Consider creating a special no-op marker class or interface in
+ * each package that serves no purpose other than being referenced by this attribute.
+ */
+ Class>[] basePackageClasses() default {};
+
+ /**
+ * Specifies which types are eligible for component scanning. Further narrows the set of candidate components from
+ * everything in {@link #basePackages()} to everything in the base packages that matches the given filter or filters.
+ */
+ Filter[] includeFilters() default {};
+
+ /**
+ * Specifies which types are not eligible for component scanning.
+ */
+ Filter[] excludeFilters() default {};
+
+ /**
+ * Returns the postfix to be used when looking up custom repository implementations. Defaults to {@literal Impl}. So
+ * for a repository named {@code PersonRepository} the corresponding implementation class will be looked up scanning
+ * for {@code PersonRepositoryImpl}.
+ *
+ * @return
+ */
+ String repositoryImplementationPostfix() default "";
+
+ /**
+ * Configures the location of where to find the Spring Data named queries properties file. Will default to
+ * {@code META-INFO/mongo-named-queries.properties}.
+ *
+ * @return
+ */
+ String namedQueriesLocation() default "";
+
+ /**
+ * Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to
+ * {@link Key#CREATE_IF_NOT_FOUND}.
+ *
+ * @return
+ */
+ Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND;
+
+ /**
+ * Returns the {@link FactoryBean} class to be used for each repository instance. Defaults to
+ * {@link MongoRepositoryFactoryBean}.
+ *
+ * @return
+ */
+ Class> repositoryFactoryBeanClass() default MongoRepositoryFactoryBean.class;
+
+ /**
+ * Configures the name of the {@link MongoTemplate} bean to be used with the repositories detected.
+ *
+ * @return
+ */
+ String mongoTemplateRef() default "mongoTemplate";
+
+ /**
+ * Whether to automatically create indexes for query methods defined in the repository interface.
+ *
+ * @return
+ */
+ boolean createIndexesForQueryMethods() default false;
+}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoriesRegistrar.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoriesRegistrar.java
new file mode 100644
index 000000000..96b8c317a
--- /dev/null
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoriesRegistrar.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2012 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.data.mongodb.repository.config;
+
+import java.lang.annotation.Annotation;
+
+import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
+import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport;
+import org.springframework.data.repository.config.RepositoryConfigurationExtension;
+
+/**
+ * Mongo-specific {@link ImportBeanDefinitionRegistrar}.
+ *
+ * @author Oliver Gierke
+ */
+class MongoRepositoriesRegistrar extends RepositoryBeanDefinitionRegistrarSupport {
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport#getAnnotation()
+ */
+ @Override
+ protected Class extends Annotation> getAnnotation() {
+ return EnableMongoRepositories.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport#getExtension()
+ */
+ @Override
+ protected RepositoryConfigurationExtension getExtension() {
+ return new MongoRepositoryConfigurationExtension();
+ }
+}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoryConfigParser.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoryConfigParser.java
deleted file mode 100644
index 5c4841f03..000000000
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoryConfigParser.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2011 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.data.mongodb.repository.config;
-
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.data.mongodb.repository.config.SimpleMongoRepositoryConfiguration.MongoRepositoryConfiguration;
-import org.springframework.data.repository.config.AbstractRepositoryConfigDefinitionParser;
-import org.w3c.dom.Element;
-
-/**
- * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} to create Mongo DB repositories from classpath
- * scanning or manual definition.
- *
- * @author Oliver Gierke
- */
-public class MongoRepositoryConfigParser extends
- AbstractRepositoryConfigDefinitionParser {
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.repository.config.AbstractRepositoryConfigDefinitionParser#getGlobalRepositoryConfigInformation(org.w3c.dom.Element)
- */
- @Override
- protected SimpleMongoRepositoryConfiguration getGlobalRepositoryConfigInformation(Element element) {
-
- return new SimpleMongoRepositoryConfiguration(element);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.repository.config.AbstractRepositoryConfigDefinitionParser#postProcessBeanDefinition(org.springframework.data.repository.config.SingleRepositoryConfigInformation, org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.beans.factory.support.BeanDefinitionRegistry, java.lang.Object)
- */
- @Override
- protected void postProcessBeanDefinition(MongoRepositoryConfiguration context, BeanDefinitionBuilder builder,
- BeanDefinitionRegistry registry, Object beanSource) {
-
- builder.addPropertyReference("mongoOperations", context.getMongoTemplateRef());
- builder.addPropertyValue("createIndexesForQueryMethods", context.getCreateQueryIndexes());
- }
-}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoryConfigurationExtension.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoryConfigurationExtension.java
new file mode 100644
index 000000000..27395d8cb
--- /dev/null
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/MongoRepositoryConfigurationExtension.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2012 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.data.mongodb.repository.config;
+
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.core.annotation.AnnotationAttributes;
+import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean;
+import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
+import org.springframework.data.repository.config.RepositoryConfigurationExtension;
+import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
+import org.springframework.data.repository.config.XmlRepositoryConfigurationSource;
+import org.w3c.dom.Element;
+
+/**
+ * {@link RepositoryConfigurationExtension} for MongoDB.
+ *
+ * @author Oliver Gierke
+ */
+public class MongoRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
+
+ private static final String MONGO_TEMPLATE_REF = "mongo-template-ref";
+ private static final String CREATE_QUERY_INDEXES = "create-query-indexes";
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModulePrefix()
+ */
+ @Override
+ protected String getModulePrefix() {
+ return "mongo";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryFactoryClassName()
+ */
+ public String getRepositoryFactoryClassName() {
+ return MongoRepositoryFactoryBean.class.getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.XmlRepositoryConfigurationSource)
+ */
+ @Override
+ public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) {
+
+ Element element = config.getElement();
+
+ String attribute = element.getAttribute(MONGO_TEMPLATE_REF);
+ builder.addPropertyReference("mongoOperations", attribute);
+
+ attribute = element.getAttribute(CREATE_QUERY_INDEXES);
+ builder.addPropertyValue("createIndexesForQueryMethods", attribute);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource)
+ */
+ @Override
+ public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {
+
+ AnnotationAttributes attributes = config.getAttributes();
+
+ builder.addPropertyReference("mongoOperations", attributes.getString("mongoTemplateRef"));
+ builder.addPropertyValue("createIndexesForQueryMethods", attributes.getBoolean("createIndexesForQueryMethods"));
+ }
+}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/SimpleMongoRepositoryConfiguration.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/SimpleMongoRepositoryConfiguration.java
deleted file mode 100644
index 7fe5af2ce..000000000
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/config/SimpleMongoRepositoryConfiguration.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright 2011 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.data.mongodb.repository.config;
-
-import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean;
-import org.springframework.data.repository.config.AutomaticRepositoryConfigInformation;
-import org.springframework.data.repository.config.ManualRepositoryConfigInformation;
-import org.springframework.data.repository.config.RepositoryConfig;
-import org.springframework.data.repository.config.SingleRepositoryConfigInformation;
-import org.springframework.util.StringUtils;
-import org.w3c.dom.Element;
-
-/**
- * {@link RepositoryConfig} implementation to create {@link MongoRepositoryConfiguration} instances for both automatic
- * and manual configuration.
- *
- * @author Oliver Gierke
- */
-public class SimpleMongoRepositoryConfiguration
- extends
- RepositoryConfig {
-
- private static final String MONGO_TEMPLATE_REF = "mongo-template-ref";
- private static final String CREATE_QUERY_INDEXES = "create-query-indexes";
- private static final String DEFAULT_MONGO_TEMPLATE_REF = "mongoTemplate";
-
- /**
- * Creates a new {@link SimpleMongoRepositoryConfiguration} for the given {@link Element}.
- *
- * @param repositoriesElement
- */
- protected SimpleMongoRepositoryConfiguration(Element repositoriesElement) {
-
- super(repositoriesElement, MongoRepositoryFactoryBean.class.getName());
- }
-
- /**
- * Returns the bean name of the {@link org.springframework.data.mongodb.core.core.MongoTemplate} to be referenced.
- *
- * @return
- */
- public String getMongoTemplateRef() {
-
- String templateRef = getSource().getAttribute(MONGO_TEMPLATE_REF);
- return StringUtils.hasText(templateRef) ? templateRef : DEFAULT_MONGO_TEMPLATE_REF;
- }
-
- /**
- * Returns whether to create indexes for query methods.
- *
- * @return
- */
- public boolean getCreateQueryIndexes() {
-
- String createQueryIndexes = getSource().getAttribute(CREATE_QUERY_INDEXES);
- return StringUtils.hasText(createQueryIndexes) ? Boolean.parseBoolean(createQueryIndexes) : false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.data.repository.config.GlobalRepositoryConfigInformation
- * #getAutoconfigRepositoryInformation(java.lang.String)
- */
- public MongoRepositoryConfiguration getAutoconfigRepositoryInformation(String interfaceName) {
-
- return new AutomaticMongoRepositoryConfiguration(interfaceName, this);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.data.repository.config.RepositoryConfig#getNamedQueriesLocation()
- */
- public String getNamedQueriesLocation() {
- return "classpath*:META-INF/mongo-named-queries.properties";
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.data.repository.config.RepositoryConfig#
- * createSingleRepositoryConfigInformationFor(org.w3c.dom.Element)
- */
- @Override
- protected MongoRepositoryConfiguration createSingleRepositoryConfigInformationFor(Element element) {
-
- return new ManualMongoRepositoryConfiguration(element, this);
- }
-
- /**
- * Simple interface for configuration values specific to Mongo repositories.
- *
- * @author Oliver Gierke
- */
- public interface MongoRepositoryConfiguration extends
- SingleRepositoryConfigInformation {
-
- String getMongoTemplateRef();
-
- boolean getCreateQueryIndexes();
- }
-
- /**
- * Implements manual lookup of the additional attributes.
- *
- * @author Oliver Gierke
- */
- private static class ManualMongoRepositoryConfiguration extends
- ManualRepositoryConfigInformation implements MongoRepositoryConfiguration {
-
- /**
- * Creates a new {@link ManualMongoRepositoryConfiguration} for the given {@link Element} and parent.
- *
- * @param element
- * @param parent
- */
- public ManualMongoRepositoryConfiguration(Element element, SimpleMongoRepositoryConfiguration parent) {
-
- super(element, parent);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.data.mongodb.repository.config.
- * SimpleMongoRepositoryConfiguration
- * .MongoRepositoryConfiguration#getMongoTemplateRef()
- */
- public String getMongoTemplateRef() {
-
- return getAttribute(MONGO_TEMPLATE_REF);
- }
-
- /* (non-Javadoc)
- * @see org.springframework.data.mongodb.config.SimpleMongoRepositoryConfiguration.MongoRepositoryConfiguration#getCreateQueryIndexes()
- */
- public boolean getCreateQueryIndexes() {
-
- String attribute = getAttribute(CREATE_QUERY_INDEXES);
- return attribute == null ? false : Boolean.parseBoolean(attribute);
- }
- }
-
- /**
- * Implements the lookup of the additional attributes during automatic configuration.
- *
- * @author Oliver Gierke
- */
- private static class AutomaticMongoRepositoryConfiguration extends
- AutomaticRepositoryConfigInformation implements MongoRepositoryConfiguration {
-
- /**
- * Creates a new {@link AutomaticMongoRepositoryConfiguration} for the given interface and parent.
- *
- * @param interfaceName
- * @param parent
- */
- public AutomaticMongoRepositoryConfiguration(String interfaceName, SimpleMongoRepositoryConfiguration parent) {
-
- super(interfaceName, parent);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.data.mongodb.repository.config.
- * SimpleMongoRepositoryConfiguration
- * .MongoRepositoryConfiguration#getMongoTemplateRef()
- */
- public String getMongoTemplateRef() {
-
- return getParent().getMongoTemplateRef();
- }
-
- /* (non-Javadoc)
- * @see org.springframework.data.mongodb.config.SimpleMongoRepositoryConfiguration.MongoRepositoryConfiguration#getCreateQueryIndexes()
- */
- public boolean getCreateQueryIndexes() {
- return getParent().getCreateQueryIndexes();
- }
- }
-}
diff --git a/spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.1.xsd b/spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.1.xsd
index feae5468b..9bfbb8799 100644
--- a/spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.1.xsd
+++ b/spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.1.xsd
@@ -103,15 +103,6 @@ The Mongo URI string.]]>
-
-
-
-
-
-
-
-
-
@@ -134,9 +125,6 @@ The Mongo URI string.]]>
-
-
-
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiExtensionIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiExtensionIntegrationTests.java
index fd7270464..5f05ccac6 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiExtensionIntegrationTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiExtensionIntegrationTests.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
import org.apache.webbeans.cditest.CdiTestContainer;
import org.apache.webbeans.cditest.CdiTestContainerLoader;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.data.mongodb.repository.Person;
@@ -39,11 +40,16 @@ public class CdiExtensionIntegrationTests {
container.bootContainer();
}
+ @AfterClass
+ public static void tearDown() throws Exception {
+ container.shutdownContainer();
+ }
+
@Test
public void bootstrapsRepositoryCorrectly() {
RepositoryClient client = container.getInstance(RepositoryClient.class);
- PersonRepository repository = client.getRepository();
+ CdiPersonRepository repository = client.getRepository();
assertThat(repository, is(notNullValue()));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/PersonRepository.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiPersonRepository.java
similarity index 92%
rename from spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/PersonRepository.java
rename to spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiPersonRepository.java
index f86c06397..48b1cebb1 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/PersonRepository.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/CdiPersonRepository.java
@@ -18,7 +18,7 @@ package org.springframework.data.mongodb.repository.cdi;
import org.springframework.data.mongodb.repository.Person;
import org.springframework.data.repository.Repository;
-public interface PersonRepository extends Repository {
+public interface CdiPersonRepository extends Repository {
void deleteAll();
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/RepositoryClient.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/RepositoryClient.java
index 34d681bcb..f8fd1755c 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/RepositoryClient.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/cdi/RepositoryClient.java
@@ -18,18 +18,17 @@ package org.springframework.data.mongodb.repository.cdi;
import javax.inject.Inject;
/**
- *
* @author Oliver Gierke
*/
class RepositoryClient {
@Inject
- PersonRepository repository;
+ CdiPersonRepository repository;
/**
* @return the repository
*/
- public PersonRepository getRepository() {
+ public CdiPersonRepository getRepository() {
return repository;
}
}
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/MongoRepositoriesRegistrarIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/MongoRepositoriesRegistrarIntegrationTests.java
new file mode 100644
index 000000000..26989e144
--- /dev/null
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/MongoRepositoriesRegistrarIntegrationTests.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2012 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.data.mongodb.repository.config;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
+import org.springframework.data.mongodb.repository.PersonRepository;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.mongodb.Mongo;
+
+/**
+ * Integration tests for {@link MongoRepositoriesRegistrar}.
+ *
+ * @author Oliver Gierke
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class MongoRepositoriesRegistrarIntegrationTests {
+
+ @Configuration
+ @EnableMongoRepositories(basePackages = "org.springframework.data.mongodb.repository")
+ static class Config {
+
+ @Bean
+ public MongoOperations mongoTemplate() throws Exception {
+ return new MongoTemplate(new SimpleMongoDbFactory(new Mongo(), "database"));
+ }
+ }
+
+ @Autowired
+ PersonRepository personRepository;
+
+ @Test
+ public void testConfiguration() {
+
+ }
+}
diff --git a/spring-data-mongodb/src/test/resources/geospatial.xml b/spring-data-mongodb/src/test/resources/geospatial.xml
index dcb331dc9..13a01ac35 100644
--- a/spring-data-mongodb/src/test/resources/geospatial.xml
+++ b/spring-data-mongodb/src/test/resources/geospatial.xml
@@ -3,7 +3,7 @@
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
+ http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
diff --git a/spring-data-mongodb/src/test/resources/mapping.xml b/spring-data-mongodb/src/test/resources/mapping.xml
index 6b45093c2..42c4c6799 100644
--- a/spring-data-mongodb/src/test/resources/mapping.xml
+++ b/spring-data-mongodb/src/test/resources/mapping.xml
@@ -3,7 +3,7 @@
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
+ http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
diff --git a/spring-data-mongodb/src/test/resources/namespace/db-factory-bean-custom-write-concern.xml b/spring-data-mongodb/src/test/resources/namespace/db-factory-bean-custom-write-concern.xml
index c42ab81a0..ef7b48fbe 100644
--- a/spring-data-mongodb/src/test/resources/namespace/db-factory-bean-custom-write-concern.xml
+++ b/spring-data-mongodb/src/test/resources/namespace/db-factory-bean-custom-write-concern.xml
@@ -2,7 +2,7 @@
diff --git a/spring-data-mongodb/src/test/resources/namespace/db-factory-bean.xml b/spring-data-mongodb/src/test/resources/namespace/db-factory-bean.xml
index ea91e67f7..bce7b0aaf 100644
--- a/spring-data-mongodb/src/test/resources/namespace/db-factory-bean.xml
+++ b/spring-data-mongodb/src/test/resources/namespace/db-factory-bean.xml
@@ -2,7 +2,7 @@
diff --git a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/MongoNamespaceReplicaSetTests-context.xml b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/MongoNamespaceReplicaSetTests-context.xml
index dd1890419..28003d77b 100644
--- a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/MongoNamespaceReplicaSetTests-context.xml
+++ b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/MongoNamespaceReplicaSetTests-context.xml
@@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
+ xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
diff --git a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/MongoNamespaceTests-context.xml b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/MongoNamespaceTests-context.xml
index 339d06f50..7a855c595 100644
--- a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/MongoNamespaceTests-context.xml
+++ b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/config/MongoNamespaceTests-context.xml
@@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
+ xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
diff --git a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml
index a1bffb752..06032c18d 100644
--- a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml
+++ b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml
@@ -3,9 +3,9 @@
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
+ xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
diff --git a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/RepositoryIndexCreationIntegrationTests-context.xml b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/RepositoryIndexCreationIntegrationTests-context.xml
index be635304f..d994229ba 100644
--- a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/RepositoryIndexCreationIntegrationTests-context.xml
+++ b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/RepositoryIndexCreationIntegrationTests-context.xml
@@ -3,9 +3,9 @@
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
+ xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
@@ -15,7 +15,6 @@
-
+
diff --git a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/config/MongoNamespaceIntegrationTests-context.xml b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/config/MongoNamespaceIntegrationTests-context.xml
index 2496a9430..b80e84c56 100644
--- a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/config/MongoNamespaceIntegrationTests-context.xml
+++ b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/config/MongoNamespaceIntegrationTests-context.xml
@@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:repository="http://www.springframework.org/schema/data/repository"
xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
+ xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
diff --git a/spring-data-mongodb/src/test/resources/server-jmx.xml b/spring-data-mongodb/src/test/resources/server-jmx.xml
index 2456cf7e3..7b24ed7ab 100644
--- a/spring-data-mongodb/src/test/resources/server-jmx.xml
+++ b/spring-data-mongodb/src/test/resources/server-jmx.xml
@@ -4,7 +4,7 @@
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
+ xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
diff --git a/spring-data-mongodb/src/test/resources/template-mapping.xml b/spring-data-mongodb/src/test/resources/template-mapping.xml
index 61a20872d..001d3f4fa 100644
--- a/spring-data-mongodb/src/test/resources/template-mapping.xml
+++ b/spring-data-mongodb/src/test/resources/template-mapping.xml
@@ -2,8 +2,8 @@
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
diff --git a/src/docbkx/reference/mongo-repositories.xml b/src/docbkx/reference/mongo-repositories.xml
index 9289838d6..58d2b7231 100644
--- a/src/docbkx/reference/mongo-repositories.xml
+++ b/src/docbkx/reference/mongo-repositories.xml
@@ -9,8 +9,8 @@
This chapter will point out the specialties for repository support
for MongoDB. This builds on the core repository support explained in . So make sure you've got a sound understanding
- of the basic concepts explained there.
+ linkend="repositories"/>. So make sure you've got a sound understanding of
+ the basic concepts explained there.
@@ -91,6 +91,36 @@
configure mongo-template-ref explicitly if you deviate from
this convention.
+ If you'd rather like to go with JavaConfig use the
+ @EnableMongoRepositories annotation. The
+ annotation carries the very same attributes like the namespace element. If
+ no base package is configured the infrastructure will scan the package of
+ the annotated configuration class.
+
+
+ JavaConfig for repositories
+
+ @Configuration
+@EnableMongoRepositories
+class ApplicationConfig extends AbstractMongoConfiguration {
+
+ @Override
+ protected String getDatabaseName() {
+ return "e-store";
+ }
+
+ @Override
+ public Mongo mongo() throws Exception {
+ return new Mongo();
+ }
+
+ @Override
+ protected String getMappingBasePackage() {
+ return "com.oreilly.springdata.mongodb"
+ }
+}
+
+
As our domain repository extends
PagingAndSortingRepository it provides you
with CRUD operations as well as methods for paginated and sorted access to
@@ -169,11 +199,11 @@ public class PersonRepositoryTests {
Supported keywords for query methods
-
+
-
+
-
+
@@ -370,7 +400,7 @@ Distance distance = new Distance(200, Metrics.KILOMETERS);
Geo-near queries
-
+
public interface PersonRepository extends MongoRepository<Person, String>
@@ -512,4 +542,4 @@ Page<Person> page = repository.findAll(person.lastname.contains("a"),
MongoDB queries.
-
\ No newline at end of file
+