2017-05-20 16 views
5

に私は次のようにプロジェクト構造がある春ブーツでマルチモジュールプロジェクトを開発しています:プロジェクトのpom.xmlファイルがあるアクセス親のapplication.properties春ブーツ

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) 

を:

<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> 

コアプロジェクトのpom.xmlファイルは次のとおりです。

<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> 

残りプロジェクトのpom.xmlがある:

<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> 

アプリコアプロジェクトのエントリポイントは次のとおり

@SpringBootApplication 
public class CoreApplication { 

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

APP-残りのエントリポイントプロジェクトはまったく同じように見えます。

core/src/main/resources/の中にapplication.propertiesというファイルが作成されています。このファイルにはデータベース設定などが含まれており、アプリコアプロジェクトをコンパイル/テストすることはできます。しかし、私はapplication.propertiesファイル

の欠如に関連するエラーは、データベース・タイプNONE用の組み込みデータベースドライバのクラスを決定することはできません取得するアプリ-残りのプロジェクトを実行したり、テストしようとします。組み込みデータベースが必要な場合は、サポートされているデータベースをクラスパスに入れてください。

子プロジェクトに親のapplication.propertiesファイルを読み込ませるにはどうすればよいですか?親ファイルへのシンボリックリンクを作成する必要がありますか、または明示的に親のプロパティファイルを@PropertySource経由でロードしますか?このシナリオで他の人は何をしますか?

答えて

0

構成用の別のモジュールを作成してください(configと言う)。そして、あなたのapplication.propertiesをconfig/src/main/resources /に入れてください。

同じconfigsを使用するモジュールに依存モジュールとしてconfigモジュールを追加してください。