我想将 Spring Boot 应用程序部署到 Heroku,我按照步骤创建了 jar 文件 - Survey-0.0.1-SNAPSHOT.jar。该应用程序在本地运行良好,还通过以下方式运行该应用程序:
heroku local web
工作正常。使用运行 jar 文件
java -jar target/Survey-0.0.1-SNAPSHOT.jar
也工作正常显示:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2021-05-08 15:36:07.685 INFO 23710 --- [ main] survey.SurveyApplication : Starting SurveyApplication v0.0.1-SNAPSHOT using Java 16.0.1 on karthikey with PID 23710 (/home/karthikey/Desktop/JavaPrograms/Survey/target/Survey-0.0.1-SNAPSHOT.jar started by karthikey in /home/karthikey/Desktop/JavaPrograms/Survey)
2021-05-08 15:36:07.688 INFO 23710 --- [ main] survey.SurveyApplication : No active profile set, falling back to default profiles: default
2021-05-08 15:36:08.455 INFO 23710 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-05-08 15:36:08.534 INFO 23710 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 69 ms. Found 4 JPA repository interfaces.
2021-05-08 15:36:08.925 INFO 23710 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@4e423aa2' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-08 15:36:08.928 INFO 23710 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-05-08 15:36:09.188 INFO 23710 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-05-08 15:36:09.200 INFO 23710 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-05-08 15:36:09.200 INFO 23710 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-05-08 15:36:09.247 INFO 23710 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-05-08 15:36:09.247 INFO 23710 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1513 ms
2021-05-08 15:36:09.334 WARN 23710 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-05-08 15:36:09.476 INFO 23710 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-05-08 15:36:09.537 INFO 23710 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.30.Final
2021-05-08 15:36:09.659 INFO 23710 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-05-08 15:36:09.758 INFO 23710 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-05-08 15:36:14.569 INFO 23710 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-05-08 15:36:14.588 INFO 23710 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2021-05-08 15:36:17.448 INFO 23710 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-05-08 15:36:17.460 INFO 23710 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-05-08 15:36:18.357 INFO 23710 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@2f7efd0b, org.springframework.security.web.context.SecurityContextPersistenceFilter@53a7a60c, org.springframework.security.web.header.HeaderWriterFilter@3ae126d1, org.springframework.web.filter.CorsFilter@41ad373, org.springframework.security.web.authentication.logout.LogoutFilter@326d27ac, survey.security.jwt.AuthTokenFilter@1a1f5f71, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@6a87026, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@2503ec73, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@6801b414, org.springframework.security.web.session.SessionManagementFilter@43fda8d9, org.springframework.security.web.access.ExceptionTranslationFilter@3e4e4c1, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@69f0b0f4]
2021-05-08 15:36:18.434 INFO 23710 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-05-08 15:36:18.598 INFO 23710 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-08 15:36:18.608 INFO 23710 --- [ main] survey.SurveyApplication : Started SurveyApplication in 11.38 seconds (JVM running for 11.803)
但是当我使用推送我的应用程序时
git push heroku master
该应用程序已成功构建,显示:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 310 bytes | 310.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/java
remote: -----> Java app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Executing Maven
remote: $ ./mvnw -DskipTests clean dependency:list install
remote: [INFO] Scanning for projects...
remote: [INFO]
remote: [INFO] -------------------------< com.example:Survey >-------------------------
remote: [INFO] Building Survey 0.0.1-SNAPSHOT
remote: [INFO] --------------------------------[ jar ]---------------------------------
remote: [INFO]
remote: [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ Survey ---
remote: [INFO]
remote: [INFO] --- maven-dependency-plugin:3.1.2:list (default-cli) @ Survey ---
remote: [INFO]
remote: [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ Survey ---
remote: [INFO] Using 'UTF-8' encoding to copy filtered resources.
remote: [INFO] Using 'UTF-8' encoding to copy filtered properties files.
remote: [INFO] Copying 1 resource
remote: [INFO] Copying 2 resources
remote: [INFO]
remote: [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ Survey ---
remote: [INFO] Changes detected - recompiling the module!
remote: [INFO] Compiling 27 source files to /tmp/build_f97fc166/target/classes
remote: [INFO]
remote: [INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ Survey ---
remote: [INFO] Using 'UTF-8' encoding to copy filtered resources.
remote: [INFO] Using 'UTF-8' encoding to copy filtered properties files.
remote: [INFO] skip non existing resourceDirectory /tmp/build_f97fc166/src/test/resources
remote: [INFO]
remote: [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ Survey ---
remote: [INFO] Changes detected - recompiling the module!
remote: [INFO] Compiling 1 source file to /tmp/build_f97fc166/target/test-classes
remote: [INFO]
remote: [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ Survey ---
remote: [INFO] Tests are skipped.
remote: [INFO]
remote: [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ Survey ---
remote: [INFO] Building jar: /tmp/build_f97fc166/target/Survey-0.0.1-SNAPSHOT.jar
remote: [INFO]
remote: [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ Survey ---
remote: [INFO] Installing /tmp/build_f97fc166/target/Survey-0.0.1-SNAPSHOT.jar to /tmp/codon/tmp/cache/.m2/repository/com/example/Survey/0.0.1-SNAPSHOT/Survey-0.0.1-SNAPSHOT.jar
remote: [INFO] Installing /tmp/build_f97fc166/pom.xml to /tmp/codon/tmp/cache/.m2/repository/com/example/Survey/0.0.1-SNAPSHOT/Survey-0.0.1-SNAPSHOT.pom
remote: [INFO] ------------------------------------------------------------------------
remote: [INFO] BUILD SUCCESS
remote: [INFO] ------------------------------------------------------------------------
remote: [INFO] Total time: 5.861 s
remote: [INFO] Finished at: 2021-05-08T08:34:54Z
remote: [INFO] ------------------------------------------------------------------------
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 51.9M
remote: -----> Launching...
remote: Released v34
remote: https://survey-it-up.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/survey-it-up.git
1dddca6..dfc71c2 master -> master
但是,在打开应用程序时,我收到一个Application Error。我的 Heroku 日志显示:
2021-05-08T08:28:30.262404+00:00 heroku[web.1]: Starting process with command `java -jar target/Survey-0.0.1-SNAPSHOT.jar`
2021-05-08T08:28:33.256619+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-05-08T08:28:33.267118+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-05-08T08:28:34.111253+00:00 app[web.1]: no main manifest attribute, in target/Survey-0.0.1-SNAPSHOT.jar
2021-05-08T08:28:34.221069+00:00 heroku[web.1]: Process exited with status 1
2021-05-08T08:28:34.316998+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-08T08:28:41.429441+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=survey-it-up.herokuapp.com request_id=88005eec-9e4c-4cd0-9c15-e2f69139a5aa fwd="157.47.209.28" dyno= connect= service= status=503 bytes= protocol=https
2021-05-08T08:28:41.812244+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=survey-it-up.herokuapp.com request_id=880bb93c-4805-4436-b70d-0fb1136cbd59 fwd="157.47.209.28" dyno= connect= service= status=503 bytes= protocol=https
我的档案:
web: java -jar target/Survey-0.0.1-SNAPSHOT.jar
我还在 MANIFEST.MF 文件中指定了主类,它在本地运行良好。我的 MANIFEST.MF 文件:
Manifest-Version: 1.0
Created-By: Maven Jar Plugin 3.2.0
Build-Jdk-Spec: 16
Implementation-Title: Survey
Implementation-Version: 0.0.1-SNAPSHOT
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: survey.SurveyApplication
Spring-Boot-Version: 2.4.5
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>Survey</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Survey</name>
<description>A web application for hoisting surveys</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
我认为在部署到 Heroku 时,它会运行:
mvn clean install
它以某种方式更改了 MANIFEST.MF 文件,例如采用不包含主类属性的默认 MANIFEST.MF。我不明白为什么即使在指定主类之后它也没有给出主清单错误。请帮帮我。
我通过删除<pluginManagement>
pom.xml 文件的 build 部分下的解决了错误。似乎 Heroku 没有读取<pluginManagement>
,删除它后,应用程序成功部署到 Heroku。删除标签后,我按照以下步骤操作:
mvn package
上述命令构建项目并将生成的JAR文件打包到目标目录中,然后运行
git push heroku master
将应用程序推送到 Heroku。
注意:我将插件包含在下面<pluginManagement>
是因为 Eclipse 显示插件错误,但即使这样程序仍然运行。所以似乎对<pluginManagement>
标签没有要求。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句