Answer the question
In order to leave comments, you need to log in
How to properly import database configuration from another module?
In general, I decided to move such things as the database configuration into a separate module (modul1)
It looks something like this:
package com.myproj.additional.common.configuration.database;
import com.mongodb.MongoClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import java.util.ArrayList;
import java.util.Collection;
@Configuration
@PropertySource("classpath:properties/base/mongodb.properties")
@EnableMongoRepositories
public class MongoConfiguration extends AbstractMongoConfiguration {
@Value("${mongodb.url}")
private String mongoUrl;
@Value("${mongo.database}")
private String mongoDatabase;
@Value("${base.packages}")
private String basePakages;
@Override
public MongoClient mongoClient() {
return new MongoClient("localhost");
}
@Override
public String getDatabaseName() {
return "myproj";
}
@Override
public Collection<String> getMappingBasePackages() {
return new ArrayList<String>() {{
// TODO
add("com.myproj.additional");
}};
}
}
package com.myproj.additional.analyzer.repository.mongo;
import com.myproj.additional.analyzer.model.mongo.Url;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository("urlRepository")
public interface UrlRepository extends CrudRepository<Url, Long> {
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question