Can't deploy Spring boot to Heroku - Error starting Tomcat context

Viewed 25

I've build successed and at my localhost the application running fine!. But when i deploy it to heroku, many errors appear.

LOGS:

2022-09-17T16:37:01.208733+00:00 heroku[web.1]: Starting process with command `java -jar target/ElectricComponentsShop-0.0.1-SNAPSHOT.jar`
2022-09-17T16:37:01.986738+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2022-09-17T16:37:01.991726+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8 
2022-09-17T16:37:03.362082+00:00 app[web.1]: 
2022-09-17T16:37:03.362123+00:00 app[web.1]:   .   ____          _            __ _ _
2022-09-17T16:37:03.364667+00:00 app[web.1]:  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2022-09-17T16:37:03.364717+00:00 app[web.1]: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2022-09-17T16:37:03.364764+00:00 app[web.1]:  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2022-09-17T16:37:03.364811+00:00 app[web.1]:   '  |____| .__|_| |_|_| |_\__, | / / / /
2022-09-17T16:37:03.364857+00:00 app[web.1]:  =========|_|==============|___/=/_/_/_/
2022-09-17T16:37:03.366804+00:00 app[web.1]:  :: Spring Boot ::                (v2.7.0)
2022-09-17T16:37:03.369426+00:00 app[web.1]: 
2022-09-17T16:37:03.585109+00:00 app[web.1]: 2022-09-17 16:37:03.581  INFO 4 --- [           main] c.e.e.ElectricComponentsShopApplication  : Starting ElectricComponentsShopApplication v0.0.1-SNAPSHOT using Java 11.0.16.1 on 426a6980-ff8e-4e47-ab90-253a0f760c00 with PID 4 (/app/target/ElectricComponentsShop-0.0.1-SNAPSHOT.jar started by u16783 in /app)
2022-09-17T16:37:03.586269+00:00 app[web.1]: 2022-09-17 16:37:03.586  INFO 4 --- [           main] c.e.e.ElectricComponentsShopApplication  : No active profile set, falling back to 1 default profile: "default"
2022-09-17T16:37:04.937777+00:00 app[web.1]: 2022-09-17 16:37:04.937  INFO 4 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-09-17T16:37:05.309570+00:00 app[web.1]: 2022-09-17 16:37:05.309  INFO 4 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 360 ms. Found 20 JPA repository interfaces.
2022-09-17T16:37:06.035011+00:00 app[web.1]: 2022-09-17 16:37:06.034  INFO 4 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-09-17T16:37:06.048182+00:00 app[web.1]: 2022-09-17 16:37:06.048  INFO 4 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-09-17T16:37:06.048341+00:00 app[web.1]: 2022-09-17 16:37:06.048  INFO 4 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.63]
2022-09-17T16:37:06.131054+00:00 app[web.1]: 2022-09-17 16:37:06.130  INFO 4 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-09-17T16:37:06.131155+00:00 app[web.1]: 2022-09-17 16:37:06.131  INFO 4 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2441 ms
2022-09-17T16:37:06.221884+00:00 app[web.1]: 2022-09-17 16:37:06.221  WARN 4 --- [           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
2022-09-17T16:37:06.243434+00:00 app[web.1]: 2022-09-17 16:37:06.243 ERROR 4 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'openEntityManagerInViewInterceptorConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]: Unsatisfied dependency expressed through method 'openEntityManagerInViewInterceptorConfigurer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openEntityManagerInViewInterceptor' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.postgresql.Driver
2022-09-17T16:37:06.269467+00:00 app[web.1]: 2022-09-17 16:37:06.269  INFO 4 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-09-17T16:37:06.281831+00:00 app[web.1]: 2022-09-17 16:37:06.281  WARN 4 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2022-09-17T16:37:06.296577+00:00 app[web.1]: 2022-09-17 16:37:06.296  INFO 4 --- [           main] ConditionEvaluationReportLoggingListener : 
2022-09-17T16:37:06.296582+00:00 app[web.1]: 
2022-09-17T16:37:06.296583+00:00 app[web.1]: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-09-17T16:37:06.329437+00:00 app[web.1]: 2022-09-17 16:37:06.328 ERROR 4 --- [           main] o.s.boot.SpringApplication               : Application run failed
2022-09-17T16:37:06.329439+00:00 app[web.1]: 
2022-09-17T16:37:06.329441+00:00 app[web.1]: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2022-09-17T16:37:06.329442+00:00 app[web.1]:    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329442+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.20.jar!/:5.3.20]
2022-09-17T16:37:06.329443+00:00 app[web.1]:    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329443+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329444+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329444+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329444+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329445+00:00 app[web.1]:    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329445+00:00 app[web.1]:    at com.example.electriccomponentsshop.ElectricComponentsShopApplication.main(ElectricComponentsShopApplication.java:11) ~[classes!/:0.0.1-SNAPSHOT]
2022-09-17T16:37:06.329446+00:00 app[web.1]:    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
2022-09-17T16:37:06.329446+00:00 app[web.1]:    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
2022-09-17T16:37:06.329447+00:00 app[web.1]:    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
2022-09-17T16:37:06.329447+00:00 app[web.1]:    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
2022-09-17T16:37:06.329448+00:00 app[web.1]:    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[ElectricComponentsShop-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
2022-09-17T16:37:06.329449+00:00 app[web.1]:    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[ElectricComponentsShop-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
2022-09-17T16:37:06.329449+00:00 app[web.1]:    at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) ~[ElectricComponentsShop-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
2022-09-17T16:37:06.329450+00:00 app[web.1]:    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) ~[ElectricComponentsShop-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
2022-09-17T16:37:06.329450+00:00 app[web.1]: Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2022-09-17T16:37:06.329450+00:00 app[web.1]:    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329450+00:00 app[web.1]:    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329451+00:00 app[web.1]:    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479) ~[spring-boot-2.7.0.jar!/:2.7.0]
2022-09-17T16:37:06.329452+00:00 app[web.1]:    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211) ~[spring-boot-2.7.0.jar!/:2.7.0]

My Dependencies:

  <properties>
        <java.version>11</java.version>
<!--        <repackage.classifier/>-->
<!--        <spring-native.version>0.12.0</spring-native.version>-->
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</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.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>2.4.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.2.3.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator-annotation-processor</artifactId>
            <version>6.2.3.Final</version>
        </dependency>




        <dependency>
            <groupId>com.j256.ormlite</groupId>
            <artifactId>ormlite-core</artifactId>
            <version>5.1</version>
        </dependency>

        <dependency>
            <groupId>com.j256.ormlite</groupId>
            <artifactId>ormlite-jdbc</artifactId>
            <version>5.1</version>
        </dependency>


    </dependencies>
 <plugins>
<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.2.2.RELEASE</version>
                <configuration>
                    <mainClass>com.example.electriccomponentsshop.ElectricComponentsShopApplication</mainClass>
                </configuration>
            </plugin>
</plugins>

My Procfile

web: java -jar target/ElectricComponentsShop-0.0.1-SNAPSHOT.jar

application.properties

spring.datasource.url= ${JDBC_DATABASE_URL:}
spring.datasource.driverClassName= ${JDBC_DATABASE_DRIVER:}
spring.datasource.username = ${JDBC_DATABASE_USERNAME:}
spring.datasource.password = ${JDBC_DATABASE_PASSWORD:}
#spring.security.user.name=user
#spring.security.user.password=pass

spring.jpa.properties.hibernate.dialect = ${SPRING_JPA_HIBERNATE_DIALECT:}
spring.jpa.generate-ddl = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.show_sql = true
spring.jpa.properties.hibernate.use_sql_comments = true
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.defer-datasource-initialization = true
logging.level.org.hibernate.SQL = DEBUG
logging.level.org.hibernate.type = TRACE
#server.port=8083

# App Properties
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
bezkoder.app.jwtSecret= bezKoderSecretKey
bezkoder.app.jwtExpirationMs= 10000
bezkoder.app.jwtRefreshExpirationMs= 86400000

.env file

JDBC_DATABASE_URL=jdbc:postgresql://ec2-52-200-5-135.compute-1.amazonaws.com:5432/dcdddhu57gptl7
JDBC_DATABASE_USERNAME=oqhvbmwnhwxqvt
JDBC_DATABASE_PASSWORD=bed4d5ac0775dbaa0d5f1948ec36651c4f178f3c3152c34e82e376feef442a9c
JDBC_DATABASE_DRIVER=org.postgresql.Driver
SPRING_JPA_HIBERNATE_DIALECT=org.hibernate.dialect.PostgreSQL9Dialect

i spent a lot of time to understand these problems, but it is not working. Pls help me, im in a Captones Project in the University

0 Answers
Related