MongoDB support
MongoDB support is based on Spring Data MongoDB 1.5.4 (reference manual and Javadoc).
Configuration
In order to use it in your project, add the following snippet to your pom.xml:
<dependency>
<groupId>org.resthub</groupId>
<artifactId>resthub-mongodb</artifactId>
<version>2.2.0</version>
</dependency>
In order to import the default configuration,
your should activate the resthub-mongodb Spring profile in your WebAppInitializer
class:
XmlWebApplicationContext appContext = new XmlWebApplicationContext();
appContext.getEnvironment().setActiveProfiles("resthub-mongodb", "resthub-web-server");
You also need to add an applicationContext.xml
file in order to scan your repository package.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
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">
<mongo:repositories base-package="com.myproject.repository" />
</beans>
You can customize them by adding a database.properties resource with one or more following keys customized with your values. You should include only the customized ones.
RESThub MongoDB default properties are:
database.dbname = resthub
database.host = localhost
database.port = 27017
database.username =
database.password =
database.connectionsPerHost = 10
database.threadsAllowedToBlockForConnectionMultiplier = 5
database.connectTimeout = 0
database.maxWaitTime = 120000
database.autoConnectRetry = false
database.socketKeepAlive = false
database.socketTimeout = 0
database.slaveOk = false
database.writeNumber = 0
database.writeTimeout = 0
database.writeFsync = false
Usage
public interface TodoRepository extends MongoRepository<Todo, String> {
List<Todo> findByContentLike(String content);
}