If you are using context XML add the following in your XML and define the database configurations.
<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/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">
<mongo:mongo-client credentials="user:password@database" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongo" ref="mongo"/>
<constructor-arg name="databaseName" value="myDBName"/>
</bean>
</beans>
Alternatively, Define a class by extending AbstractMongoConfiguration and override the getDatabaseName().
@Configuration
public class SpringDBConfig extends AbstractMongoConfiguration
{
@Override
protected String getDatabaseName() {
return "testdatabase";
}
......
}
Documentname (table name) for classes?