2017-05-22 1 views
2

私はspring-boot Webアプリケーションを持っています。私はfront-endをangular-cliで構築します。私はリソースへangular-cli.json /静的に私の角度のビルドの出力ディレクトリを設定していると私はこのようなpackage.jsonでビルドスクリプトを設定している:私は設定している春ブート構成のapplication.propertiesで角度2フロントエンド(angular-cli build)のスプリングブートwebappをTomcatにどのように配備できますか?

"scripts" : {"build": "ng build --base-href /mywebapp", ...} 

server.contextPathを 'mywebapp'に設定します。

しかし、私は角度のアプリケーションをビルドする場合は、リソース/静的で作成したindex.htmlのJS含まれているファイルは、サーバコンテキストパス「mywebapp」が含まれていません。

<script type="text/javascript" src="inline.bundle.js"></script> 
<script type="text/javascript" src="polyfills.bundle.js"></script> 

を私は次のようになります。私はTomcatに私の春ブートアプリをデプロイした場合

<script type="text/javascript" src="/mywebapp/inline.bundle.js"></script> 
<script type="text/javascript" src="/mywebapp/polyfills.bundle.js"></script> 

だから建てのindex.htmlは、負荷であるが、それはインポートされたJSファイルを見つけることができないとhttp://localhost:8080/の代わりhttp://localhost:8080/mywebapp/下のファイルをロードしようとします。

フロントエンドを備えたスプリングブートアプリケーションをTomcatサーバーに展開するには、ルートディレクトリの下に展開したくない場合はどうすればいいですか?

+0

あなたはそれをやる方法を尋ねているので面白いですし、あなたが実際にそれをする方法を示しているので、私は見つけられませんでした。あなたの本当の疑問は、「どのようにAngularとSpringを特定のパスに配備できますか?」です。 – GabrielBB

答えて

1

「--deploy-url」パラメータを使用して私の答えを見てください。あなたのケースでは

https://stackoverflow.com/a/43741602/5633515、最初に私はpom.xmlファイルを作成しましたし、そこに私は戦争のファイルに私のパッケージを変換するためのプラグインを使用しました、--deploy-url="/mywebapp/"

+0

ありがとうございました。今、私はURL http:// localhost:8080/mywebapp /の下で自分のフロントエンドにアクセスできます。しかし、一つの問題が残っている。ブラウザで角度のあるルータリンクURL(http:// localhost:8080/mywebapp/feature1 /)を更新したい場合は、もう動作しません。角度のあるアプリケーションは、http:// localhost:8080/mywebapp/feature1 /に正しく移動しますが、このURLのリフレッシュだけがもう機能しません。角度のあるルートURLのリフレッシュは動作します(http:// localhost:8080/mywebapp /) – surfspider

+0

これは私にはコードの問題があり、ロードされている角に関係していないようです。あなたは、その機能のURLをリフレッシュする際に正しい角度のスクリプトタグを見ますか?コンソールエラーが表示されますか? –

+0

ここで解決策を見つけました:https://stackoverflow.com/questions/44132284/problems-with-angular-deploy-url-switch – surfspider

0

が、私は同じ質問をしました使用しています。

<plugins> 

    <!-- ############################## --> 
    <!-- npm scripts     --> 
    <!-- ############################## --> 

    <plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>exec-project-dependencies-install</id> 
     <phase>generate-sources</phase> 
     <configuration> 
      <executable>npm</executable> 
      <arguments> 
      <argument>install</argument> 
      </arguments> 
     </configuration> 
     <goals> 
      <goal>exec</goal> 
     </goals> 
     </execution> 

     <!-- run `ng build -prod -aot` --> 
     <!-- * clean dist/ before generating distribution files --> 
     <execution> 
     <id>exec-compile</id> 
     <phase>generate-sources</phase> 
     <configuration> 
      <executable>npm</executable> 
      <arguments> 
      <argument>run</argument> 
      <argument>ci</argument> 
      </arguments> 
     </configuration> 
     <goals> 
      <goal>exec</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 

    <!-- generate zip --> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
     <descriptors> 
     <descriptor>src/assembly/static.xml</descriptor> 
     </descriptors> 
    </configuration> 
    <executions> 
     <execution> 
     <id>make-assembly</id> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 
    <!--generate zip --> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
     <descriptors> 
     <descriptor>src/assembly/static.xml</descriptor> 
     </descriptors> 
    </configuration> 
    <executions> 
     <execution> 
     <id>make-assembly</id> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 

展開私はいくつかの問題と良い講義を見つけたとき。

理論 - https://kosbr.github.io/2016/10/09/angular-build.html

問題 - https://github.com/angular/angular-cli/issues/4517 - https://github.com/angular/angular-cli/pull/4090

はそれが役に立てば幸い。

関連する問題