R
R
reus2017-11-02 17:24:51
Spring
reus, 2017-11-02 17:24:51

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");
        }};
    }
}

This configuration is imported by modul2. In turn, modul2 contains approximately the following repository:
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> {
}

The imported configuration from modul1 does not see the repository from modul2.
Tell me how to put the javaconf database into a separate module and at the same time so that it can see the repositories of the modules that import it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question