java-使用war将spring-boot和angular 7应用程序部署到tomcat 8.5中

前端之家收集整理的这篇文章主要介绍了java-使用war将spring-boot和angular 7应用程序部署到tomcat 8.5中 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试使用war将Angular 7 Spring Boot应用程序部署到tomcat中.我遵循了一些步骤来用角度代码发动战争.使用UI代码成功创建了战争.但是我无法调用UI代码.
当我尝试打电话时

>本地主机:8080 / war-name
>本地主机:8080 / war-name / index.html
>本地主机:8080 / index.html

显示404.

Web服务正常运行.我可以打电话给他们.

如何调用应用程序的index.html?

注意:-我没有使用spring-boot-starter-web

pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.1.3.RELEASE</version>
  9. <relativePath /> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.hackthon</groupId>
  12. <artifactId>pmoconnect</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>pmoconnect</name>
  15. <description>PMO Connect</description>
  16. <packaging>war</packaging>
  17. <properties>
  18. <java.version>1.8</java.version>
  19. <start-class>com.hackthon.HackthonApplication</start-class>
  20. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  21. </properties>
  22. <dependencies>
  23. <dependency>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter-data-jpa</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework.boot</groupId>
  29. <artifactId>spring-boot-starter-jersey</artifactId>
  30. </dependency>
  31. <dependency>
  32. <groupId>org.springframework.boot</groupId>
  33. <artifactId>spring-boot-starter-test</artifactId>
  34. <scope>test</scope>
  35. </dependency>
  36. <dependency>
  37. <groupId>MysqL</groupId>
  38. <artifactId>MysqL-connector-java</artifactId>
  39. <scope>runtime</scope>
  40. </dependency>
  41. <dependency>
  42. <groupId>org.apache.commons</groupId>
  43. <artifactId>commons-lang3</artifactId>
  44. </dependency>
  45. <dependency>
  46. <groupId>org.apache.poi</groupId>
  47. <artifactId>poi</artifactId>
  48. <version>4.0.1</version>
  49. </dependency>
  50. <!-- excel 2007 over -->
  51. <dependency>
  52. <groupId>org.apache.poi</groupId>
  53. <artifactId>poi-ooxml</artifactId>
  54. <version>4.0.1</version>
  55. </dependency>
  56. <dependency>
  57. <groupId>org.glassfish.jersey.media</groupId>
  58. <artifactId>jersey-media-multipart</artifactId>
  59. </dependency>
  60. <dependency>
  61. <groupId>org.springframework.boot</groupId>
  62. <artifactId>spring-boot-devtools</artifactId>
  63. </dependency>
  64. <dependency>
  65. <groupId>com.sun.mail</groupId>
  66. <artifactId>javax.mail</artifactId>
  67. <version>1.5.5</version>
  68. </dependency>
  69. <dependency>
  70. <groupId>org.hibernate</groupId>
  71. <artifactId>hibernate-envers</artifactId>
  72. <version>${hibernate.version}</version>
  73. </dependency>
  74. </dependencies>
  75. <build>
  76. <plugins>
  77. <plugin>
  78. <groupId>com.github.eirslett</groupId>
  79. <artifactId>frontend-maven-plugin</artifactId>
  80. <version>1.3</version>
  81. <configuration>
  82. <nodeVersion>v8.11.3</nodeVersion>
  83. <npmVersion>6.3.0</npmVersion>
  84. <workingDirectory>src/main/ngapp/</workingDirectory>
  85. </configuration>
  86. <executions>
  87. <execution>
  88. <id>install node and npm</id>
  89. <goals>
  90. <goal>install-node-and-npm</goal>
  91. </goals>
  92. </execution>
  93. <execution>
  94. <id>npm install</id>
  95. <goals>
  96. <goal>npm</goal>
  97. </goals>
  98. </execution>
  99. <execution>
  100. <id>npm run build</id>
  101. <goals>
  102. <goal>npm</goal>
  103. </goals>
  104. <configuration>
  105. <arguments>run build</arguments>
  106. </configuration>
  107. </execution>
  108. <execution>
  109. <id>prod</id>
  110. <goals>
  111. <goal>npm</goal>
  112. </goals>
  113. <configuration>
  114. <arguments>run-script build</arguments>
  115. </configuration>
  116. <phase>generate-resources</phase>
  117. </execution>
  118. </executions>
  119. </plugin>
  120. <plugin>
  121. <artifactId>maven-resources-plugin</artifactId>
  122. <executions>
  123. <execution>
  124. <id>copy-resources</id>
  125. <phase>validate</phase>
  126. <goals>
  127. <goal>copy-resources</goal>
  128. </goals>
  129. <configuration>
  130. <outputDirectory>${project.build.directory}/classes/static/</outputDirectory>
  131. <!-- <outputDirectory>${project.build.directory}/../src/main/resources/static/</outputDirectory> -->
  132. <resources>
  133. <resource>
  134. <directory>/src/main/ngapp/dist/</directory>
  135. </resource>
  136. </resources>
  137. </configuration>
  138. </execution>
  139. </executions>
  140. </plugin>
  141. <plugin>
  142. <groupId>org.apache.maven.plugins</groupId>
  143. <artifactId>maven-failsafe-plugin</artifactId>
  144. </plugin>
  145. <plugin>
  146. <groupId>org.apache.maven.plugins</groupId>
  147. <artifactId>maven-surefire-plugin</artifactId>
  148. </plugin>
  149. <plugin>
  150. <groupId>org.springframework.boot</groupId>
  151. <artifactId>spring-boot-maven-plugin</artifactId>
  152. </plugin>
  153. <plugin>
  154. <groupId>org.apache.maven.plugins</groupId>
  155. <artifactId>maven-war-plugin</artifactId>
  156. <configuration>
  157. <packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
  158. <warName>pmoconnect</warName>
  159. </configuration>
  160. </plugin>
  161. </plugins>
  162. </build>
  163. </project>

application.properties

  1. spring.datasource.url = jdbc:MysqL://localhost:3306/elite_db?allowPublicKeyRetrieval=true&useSSL=false
  2. spring.datasource.username = <username>
  3. spring.datasource.password = <password>
  4. ## Hibernate Properties
  5. # The sql dialect makes Hibernate generate better sql for the chosen database
  6. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MysqL5InnoDBDialect
  7. spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
  8. # Hibernate ddl auto (create,create-drop,validate,update)
  9. spring.jpa.hibernate.ddl-auto = update
  10. org.hibernate.envers.audit_table_suffix = _AUDIT_LOG

HackthonApplication.java

  1. @SpringBootApplication
  2. @ComponentScan
  3. public class HackthonApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(HackthonApplication.class,args);
  6. }
  7. }

index.html

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <Meta charset="utf-8">
  5. <title>PMO Connect</title>
  6. <base href="./">
  7. <Meta name="viewport" content="width=device-width,initial-scale=1">
  8. <link rel="icon" type="image/x-icon" href="favicon.ico">
  9. <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  10. </head>
  11. <body>
  12. <app-root></app-root>
  13. <script type="text/javascript" src="runtime.js"></script>
  14. <script type="text/javascript" src="es2015-polyfills.js" nomodule></script>
  15. <script type="text/javascript" src="polyfills.js"></script>
  16. <script type="text/javascript" src="styles.js"></script>
  17. <script type="text/javascript" src="vendor.js"></script>
  18. <script type="text/javascript" src="main.js"></script>
  19. </body>
  20. </html>

战争档案

war file

Tomcat日志

  1. 2019-03-27 10:34:19.134 INFO 18464 --- [ost-startStop-2] com.hackthon.HackthonApplication : No active profile set,falling back to default profiles: default
  2. 2019-03-27 10:34:19.291 INFO 18464 --- [ost-startStop-2] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
  3. 2019-03-27 10:34:22.558 INFO 18464 --- [ost-startStop-2] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
  4. 2019-03-27 10:34:22.977 INFO 18464 --- [ost-startStop-2] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 372ms. Found 6 repository interfaces.
  5. 2019-03-27 10:34:24.386 INFO 18464 --- [ost-startStop-2] o.a.c.c.C.[.[localhost].[/pmoconnect] : Initializing Spring embedded WebApplicationContext
  6. 2019-03-27 10:34:24.386 INFO 18464 --- [ost-startStop-2] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5094 ms
  7. 2019-03-27 10:34:24.809 INFO 18464 --- [ost-startStop-2] o.s.b.a.jersey.JerseyAutoConfiguration : Configuring existing registration for Jersey servlet 'com.hackthon.config.JerseyConfiguration'
  8. 2019-03-27 10:34:25.046 INFO 18464 --- [ost-startStop-2] o.s.boot.web.servlet.RegistrationBean : Servlet com.hackthon.config.JerseyConfiguration was not registered (possibly already registered?)
  9. 2019-03-27 10:34:25.628 INFO 18464 --- [ost-startStop-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
  10. 2019-03-27 10:34:26.473 INFO 18464 --- [ost-startStop-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
  11. 2019-03-27 10:34:26.815 INFO 18464 --- [ost-startStop-2] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
  12. name: default
  13. ...]
  14. 2019-03-27 10:34:27.465 INFO 18464 --- [ost-startStop-2] org.hibernate.Version : HHH000412: Hibernate Core {5.3.7.Final}
  15. 2019-03-27 10:34:27.472 INFO 18464 --- [ost-startStop-2] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
  16. 2019-03-27 10:34:28.996 INFO 18464 --- [ost-startStop-2] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
  17. 2019-03-27 10:34:30.597 INFO 18464 --- [ost-startStop-2] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MysqL5InnoDBDialect
  18. 2019-03-27 10:34:30.951 INFO 18464 --- [ost-startStop-2] o.h.e.boot.internal.EnveRSServiceImpl : Envers integration enabled? : true
  19. 2019-03-27 10:34:41.272 INFO 18464 --- [ost-startStop-2] j.LocalContainerEntityManagerfactorybean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  20. 2019-03-27 10:34:43.158 INFO 18464 --- [ost-startStop-2] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
  21. 2019-03-27 10:34:46.554 INFO 18464 --- [ost-startStop-2] com.hackthon.HackthonApplication : Started HackthonApplication in 29.239 seconds (JVM running for 143.14)
  22. 2019-03-27 10:34:46.944 INFO 18464 --- [ost-startStop-2] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
  23. 2019-03-27 10:34:50.219 WARN 18464 --- [ost-startStop-2] org.glassfish.jersey.internal.Errors : The following warnings have been detected: WARNING: A HTTP GET method,public javax.ws.rs.core.Response com.hackthon.service.WSFGMapping.getMappings(java.lang.String),should not consume any entity.
  24. 2019-03-27 10:34:50.348 INFO 18464 --- [ost-startStop-2] org.apache.catalina.startup.HostConfig : Deployment of web application archive [C:\Users\kaukhare\myWorkspace\.Metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\pmoconnect.war] has finished in [68,229] ms
最佳答案
我也遇到了同样的问题,并通过在index.html中添加以下脚本来解决

  1. <base href="/" id="baseHref">
  2. <script>
  3. (function() {
  4. document.getElementById('baseHref').href = '/' + window.location.pathname.split('/')[1] + "/";
  5. })();
  6. </script>

我认为它将解决您的问题.

猜你在找的Spring相关文章