dirk.dinger
Apr 29th, 2011, 05:49 AM
Hi Spring data users,
Just started playing around with spring data and mongodb. Following the instructions in the reference doc I created a repository interface like this
package net.flexcellence.redux.server.dao.impl;
import net.flexcellence.redux.server.dto.RedUXAsset;
import org.springframework.data.document.mongodb.reposito ry.MongoRepository;
public interface AssetRepository extends MongoRepository<RedUXAsset, String>{}
in my applicationcontext.xml I imported the mongo namespace and added the following:
<bean id="mongo" class="com.mongodb.Mongo">
<constructor-arg value="${mongodb.host}"/>
<constructor-arg value="${mongodb.port}"/>
</bean>
<bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTem plate">
<constructor-arg ref="mongo"/>
<constructor-arg name="databaseName" value="${mongodb.dbname}"/>
</bean>
<mongo:repositories base-package="net.net.flexcellence.redux.server.dao.impl" mongo-template-ref="mongoTemplate" />
If I now write a simple unit test, based upon the repository having an autowired property like
@Autowired
private AssetRepository repository;
The Repository is not created and injected. Is there anything I am missing in my config ? Maybe aspectJ is required ?
There is a section in the reference doc "Example 4.6. Standalone usage of repository factory"
but the actual code to create the repositoy programmatically is ommitted :confused:
Any help appreciated.
Regards,
Dirk
Just started playing around with spring data and mongodb. Following the instructions in the reference doc I created a repository interface like this
package net.flexcellence.redux.server.dao.impl;
import net.flexcellence.redux.server.dto.RedUXAsset;
import org.springframework.data.document.mongodb.reposito ry.MongoRepository;
public interface AssetRepository extends MongoRepository<RedUXAsset, String>{}
in my applicationcontext.xml I imported the mongo namespace and added the following:
<bean id="mongo" class="com.mongodb.Mongo">
<constructor-arg value="${mongodb.host}"/>
<constructor-arg value="${mongodb.port}"/>
</bean>
<bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTem plate">
<constructor-arg ref="mongo"/>
<constructor-arg name="databaseName" value="${mongodb.dbname}"/>
</bean>
<mongo:repositories base-package="net.net.flexcellence.redux.server.dao.impl" mongo-template-ref="mongoTemplate" />
If I now write a simple unit test, based upon the repository having an autowired property like
@Autowired
private AssetRepository repository;
The Repository is not created and injected. Is there anything I am missing in my config ? Maybe aspectJ is required ?
There is a section in the reference doc "Example 4.6. Standalone usage of repository factory"
but the actual code to create the repositoy programmatically is ommitted :confused:
Any help appreciated.
Regards,
Dirk