2017-09-03 8 views
4

私はSpringブートとAngular 2/4プロジェクトを1つのWARにパッケージ化してTomcatに提供したいと思っています。 maven - Spring Boot/Angular 2/4プロジェクトの戦争ビルド

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>mk.edu.ukim.feit.bolt</groupId> 
<artifactId>parent</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>pom</packaging> 

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

<modules> 
    <module>api</module> 
    <module>frontend</module> 
</modules> 

親/のpom.xmlをフロントエンド/ POM:私は、次のpom.xml構成で、2つのモジュール(角度や春ブーツのための1のための1)と親プロジェクトを持っています.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<artifactId>frontend</artifactId> 


<name>Bolt Client</name> 
<description>Bolt messaging app frontend client</description> 

<parent> 
    <groupId>mk.edu.ukim.feit.bolt</groupId> 
    <artifactId>parent</artifactId> 
    <version>1.0-SNAPSHOT</version> 
</parent> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
</properties> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>com.github.eirslett</groupId> 
      <artifactId>frontend-maven-plugin</artifactId> 
      <version>1.4</version> 

      <configuration> 
       <nodeVersion>v7.9.0</nodeVersion> 
       <npmVersion>4.6.1</npmVersion> 
       <workingDirectory>src/main/frontend</workingDirectory> 
      </configuration> 

      <executions> 
       <execution> 
        <id>install node and npm</id> 
        <goals> 
         <goal>install-node-and-npm</goal> 
        </goals> 
       </execution> 

       <execution> 
        <id>npm install</id> 
        <goals> 
         <goal>npm</goal> 
        </goals> 
       </execution> 

       <execution> 
        <id>npm run prod</id> 

        <goals> 
         <goal>npm</goal> 
        </goals> 

        <configuration> 
         <arguments>run prod</arguments> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 

    <resources> 
     <resource> 
      <directory>target/frontend</directory> 
      <targetPath>static</targetPath> 
     </resource> 
    </resources> 
</build> 

API /のpom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<artifactId>api</artifactId> 
<version>1.0-SNAPSHOT</version> 

<name>Bolt API</name> 
<description>Bolt messaging app REST API</description> 
<packaging>war</packaging> 

<parent> 
    <groupId>mk.edu.ukim.feit.bolt</groupId> 
    <artifactId>parent</artifactId> 
    <version>1.0-SNAPSHOT</version> 
</parent> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-aop</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-rest</artifactId> 
    </dependency> 
    <!--<dependency>--> 
     <!--<groupId>org.springframework.boot</groupId>--> 
     <!--<artifactId>spring-boot-starter-jdbc</artifactId>--> 
    <!--</dependency>--> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web-services</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-websocket</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-mail</artifactId> 
     <version>1.5.6.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-logging</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.restdocs</groupId> 
     <artifactId>spring-restdocs-mockmvc</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.h2database</groupId> 
     <artifactId>h2</artifactId> 
     <version>${h2.version}</version> 
     <scope>compile</scope> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt --> 
    <dependency> 
     <groupId>io.jsonwebtoken</groupId> 
     <artifactId>jjwt</artifactId> 
     <version>0.6.0</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/joda-time/joda-time --> 
    <dependency> 
     <groupId>joda-time</groupId> 
     <artifactId>joda-time</artifactId> 
     <version>2.9.9</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/commons-validator/commons-validator --> 
    <dependency> 
     <groupId>commons-validator</groupId> 
     <artifactId>commons-validator</artifactId> 
     <version>1.6</version> 
    </dependency> 
    <dependency> 
     <groupId>mk.edu.ukim.feit.bolt</groupId> 
     <artifactId>frontend</artifactId> 
     <version>${project.version}</version> 
     <scope>runtime</scope> 
    </dependency> 
</dependencies> 

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

私はthisチュートリアルとIに成功MVNクリーンその後、APIディレクトリに入るとMVNスプリング・ブートを実行し、親ディレクトリからインストールを実行するプロジェクトをビルドすることになった次ました:実行し、アプリケーションがありますlocalhost:8080で提供されていますが、Mavenのwarファイルを構築している間は、Angularからコンパイルされた静的ファイルを取得せず、http://localhost:8080に404を返します。誰がここで間違っているかもしれないかについてのヒントを教えてくれますか?

"prod" NPMスクリプトを "ng build --prod --base-href = \" ./ \ ""に設定しようとしましたが、何かをしなければならないかもしれないと思っても助けになりませんでした。何か案は?

答えて

0

私が見つけた解決策:

  1. コピーサーバープロジェクトの下のシングル "index.htmlの" ファイルへ "のsrc /メイン/リソース/テンプレート" フォルダ。 HTMLファイル構造は非常に厳格でなければならないことに注意してください(開いているタグはすべて閉じなければなりません)。
  2. "インデックス" テンプレート

サンプルに "/" リクエストマッピングのためにHomeControllerを作成

  • Mavenの依存関係 "春・ブート・スターター・thymeleaf" を追加します。

    @Controller 
    public class HomeContoller { 
        @RequestMapping("/") 
        public String index() { 
         return "index"; 
        } 
    } 
    

    GitHub commit with HomeController
    を参照してください。誰かがよりクリーンな/より良い解決策を知っていて共有することができれば素晴らしいだろう。

  • 関連する問題