Browse Source
Support for considering nested repository interfaces can now be configured on the EnableMongoRepositories annotation via the considerNestedRepositories property. Original pull request: #87.pull/67/merge
5 changed files with 148 additions and 0 deletions
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
/* |
||||
* 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.data.mongodb.repository; |
||||
|
||||
/** |
||||
* @see DATAMONGO-780 |
||||
* @author Thomas Darimont |
||||
*/ |
||||
public class ClassWithNestedRepository { |
||||
|
||||
public static interface NestedUserRepository extends MongoRepository<User, Integer> {} |
||||
} |
||||
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
/* |
||||
* 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.data.mongodb.repository.config; |
||||
|
||||
import static org.hamcrest.CoreMatchers.*; |
||||
import static org.junit.Assert.*; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.data.mongodb.repository.ClassWithNestedRepository.NestedUserRepository; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
/** |
||||
* Integration test for repository namespace configuration with nested repositories. |
||||
* |
||||
* @author Thomas Darimont |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration(locations = "AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml") |
||||
public class AllowNestedMongoRepositoriesRepositoryConfigTests { |
||||
|
||||
@Autowired NestedUserRepository fooRepository; |
||||
|
||||
/** |
||||
* @see DATAMONGO-780 |
||||
*/ |
||||
@Test |
||||
public void shouldFindNestedRepository() { |
||||
assertThat(fooRepository, is(notNullValue())); |
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
/* |
||||
* 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.data.mongodb.repository.config; |
||||
|
||||
import static org.hamcrest.CoreMatchers.*; |
||||
import static org.junit.Assert.*; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.ImportResource; |
||||
import org.springframework.data.mongodb.repository.ClassWithNestedRepository.NestedUserRepository; |
||||
import org.springframework.data.mongodb.repository.PersonRepository; |
||||
import org.springframework.data.repository.support.Repositories; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
/** |
||||
* Integration test for the combination of JavaConfig and an {@link Repositories} wrapper. |
||||
* |
||||
* @author Thomas Darimont |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
public class NestedMongoRepositoriesJavaConfigTests { |
||||
|
||||
@Configuration |
||||
@EnableMongoRepositories(basePackageClasses = PersonRepository.class, considerNestedRepositories = true) |
||||
@ImportResource("classpath:infrastructure.xml") |
||||
static class Config {} |
||||
|
||||
@Autowired NestedUserRepository nestedUserRepository; |
||||
|
||||
/** |
||||
* @see DATAMONGO-780 |
||||
*/ |
||||
@Test |
||||
public void shouldSupportNestedRepositories() { |
||||
assertThat(nestedUserRepository, is(notNullValue())); |
||||
} |
||||
} |
||||
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo" |
||||
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.xsd |
||||
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.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"> |
||||
|
||||
<import resource="classpath:infrastructure.xml"/> |
||||
|
||||
<mongo:repositories base-package="org.springframework.data.mongodb.repository" consider-nested-repositories="true"/> |
||||
</beans> |
||||
Loading…
Reference in new issue