2017-05-20 6 views
5

ich ein Multi-Modul-Projektes im Frühjahr Boot-entwickle, wo die Projektstruktur ist wie folgt:Zugang Eltern application.properties von abhängigem Projekt im Frühjahr Boot

com.app.parent <- parent pom with version numbers and common dependencies (POM) 
com.app.core <- repository and service layer, models, DTOs (JAR) 
com.app.rest <- rest API (WAR) 
com.app.soap <- soap API (WAR) 

Die pom.xml-Datei für das Mutter Projekt :

<artifactId>app-parent</artifactId> 
<packaging>pom</packaging> 
<name>app-parent</name> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.3.RELEASE</version> 
    <relativePath/> 
</parent> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 

die pom.xml-Datei für den Kern Projekt ist:

<artifactId>app-core</artifactId> 
<packaging>jar</packaging> 
<name>app-core</name> 

<parent> 
    <groupId>com.app</groupId> 
    <artifactId>app-parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <relativePath>../app-parent/pom.xml</relativePath> 
</parent> 

<dependencies> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
</dependencies> 

Die pom.xml für das Rest Projekt:

<artifactId>app-rest</artifactId> 
<packaging>war</packaging> 
<name>app-rest</name> 

<parent> 
    <groupId>com.app</groupId> 
    <artifactId>app-parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <relativePath>../app-parent/pom.xml</relativePath> 
</parent> 

<dependencies> 
    <dependency> 
     <groupId>com.app</groupId> 
     <artifactId>app-core</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
</dependencies> 

der Einstiegspunkt für das app-Kern Projekt:

@SpringBootApplication 
public class CoreApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(CoreApplication.class, args); 
    } 
} 

der Einstiegspunkt für den app-Rest Das Projekt sieht genauso aus.

Ich habe eine application.properties Datei innerhalb core/src/main/resources/ erstellt, die Datenbankkonfiguration usw. enthält und ich kann das App-Core-Projekt gut kompilieren/testen. Aber wenn ich versuche, das app-Rest Projekt, das ich Fehler auf das Fehlen von application.properties Datei

bestimmen kann leider keine eingebettete Datenbanktreiber-Klasse für Datenbanktyp NONE Zusammenhang erhalten zu laufen oder zu testen. Wenn Sie eine eingebettete Datenbank wünschen, legen Sie eine unterstützte Datenbank auf den Klassenpfad.

Wie bekomme ich das untergeordnete Projekt, um die application.properties Datei des Elterns zu laden? Muss ich einen Symlink zur übergeordneten Datei erstellen oder lade ich ausdrücklich die Eigenschaftsdatei des übergeordneten Elements über @PropertySource? Was machen andere in diesem Szenario?

Antwort

0

Erstellen Sie ein anderes Modul für Konfigurationen (sagen wir Config) und setzen Sie Ihre application.properties in config/src/main/resources /.

Fügen Sie das Konfigurationsmodul als Abhängigkeit zu jedem Modul hinzu, das die gleichen Konfigurationen verwendet und Sie gehen.

Verwandte Themen