我创建了一个war,其中包含我的后端应用程序(Spring Boot)和前端应用程序(Angular2)。在前端应用程序中,我使用Angular CLI来创建分发文件。
我需要将这个war部署到WebLogic应用服务器。
为了构建前端项目,我通过exec-maven-plugin运行“ng build
”命令。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}/src/main/ngapp</workingDirectory>
<executable>npm.cmd</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-npm-ng-build</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}/src/main/ngapp</workingDirectory>
<executable>ng.cmd</executable>
<arguments>
<argument>build</argument>
<argument>--base-href=/applicationName</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
index.html
的内容
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CometTest</title>
<base href="/applicationName">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app>Loading...</app>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="scripts.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>
当我在本地机器上使用contextPath='applicationName'
将产生的war部署到Tomcat时,它工作得很好。
但是当我部署到远程WebLogic时,它在加载javascript文件时抛出错误。
Failed to load resource: the server responded with a status of 404 (Not Found) http://24.211.213.46:7611/inline.bundle.js
为什么WebLogic尝试在url中没有applicationName
的情况下下载文件?
我可以通过下面的url访问这个javascript文件:
http://24.211.213.46:7611/applicationName/inline.bundle.js
发布于 2017-06-14 21:54:07
为了正确加载我的javascript文件,我必须使用deploy-url
参数
ng build --environment=prod --deploy-url http://24.211.213.46:7611/applicationName
发布于 2017-06-07 23:57:17
我也有同样的问题。我能够通过更改路由策略来修复它,以使用如下所示的散列:
imports: [RouterModule.forRoot(APP_ROUTES, { useHash: true })]
https://stackoverflow.com/questions/44159074
复制相似问题