WebLogic 不使用上下文路径来加载 javascript 个文件
WebLogic doesn't use contextpath for loading javascript files
我创建了一个 war,其中包含我的后端应用程序(Spring Boot)和前端应用程序(Angular2)。在前端应用程序中,我使用 Angular CLI 来创建分发文件。
我需要将此 war 部署到 WebLogic 应用程序服务器。
对于构建前端项目,我 运行"ng build
" 通过 exec-maven-plugin 命令。
<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
我遇到了同样的问题。我能够通过更改路由策略以使用像这样的哈希来修复它:
imports: [RouterModule.forRoot(APP_ROUTES, { useHash: true })]
为了正确加载我的 javascript 文件,我必须使用 deploy-url
参数
ng build --environment=prod --deploy-url http://24.211.213.46:7611/applicationName
我创建了一个 war,其中包含我的后端应用程序(Spring Boot)和前端应用程序(Angular2)。在前端应用程序中,我使用 Angular CLI 来创建分发文件。
我需要将此 war 部署到 WebLogic 应用程序服务器。
对于构建前端项目,我 运行"ng build
" 通过 exec-maven-plugin 命令。
<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:
http://24.211.213.46:7611/applicationName/inline.bundle.js
我遇到了同样的问题。我能够通过更改路由策略以使用像这样的哈希来修复它:
imports: [RouterModule.forRoot(APP_ROUTES, { useHash: true })]
为了正确加载我的 javascript 文件,我必须使用 deploy-url
参数
ng build --environment=prod --deploy-url http://24.211.213.46:7611/applicationName