В Eclipse приложение работает без ошибок, и я могу без проблем подключиться к базе данных, но когда я экспортирую приложение как исполняемый jar-файл, оно не работает. и я получаю сообщение об ошибке ниже.
Код: Выделить всё
>>java -jar Runnable_tracker.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.2.3)
2024-05-05T23:59:53.729+02:00 INFO 30180 --- [ main] c.e.T.TopicArchiverApplication : Starting TopicArchiverApplication using Java 17.0.2 with PID 30180 (C:\Users\johan\eclipse-workspace\Topic_archiver\Runnable_tracker.jar started by johan in C:\Users\johan\eclipse-workspace\Topic_archiver)
2024-05-05T23:59:53.732+02:00 INFO 30180 --- [ main] c.e.T.TopicArchiverApplication : No active profile set, falling back to 1 default profile: "default"
2024-05-05T23:59:54.277+02:00 INFO 30180 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-05-05T23:59:54.326+02:00 INFO 30180 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 38 ms. Found 3 JPA repository interfaces.
2024-05-05T23:59:54.790+02:00 INFO 30180 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2024-05-05T23:59:54.800+02:00 INFO 30180 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2024-05-05T23:59:54.801+02:00 INFO 30180 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.19]
2024-05-05T23:59:54.842+02:00 INFO 30180 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-05-05T23:59:54.844+02:00 INFO 30180 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1075 ms
2024-05-05T23:59:54.892+02:00 WARN 30180 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
2024-05-05T23:59:54.895+02:00 INFO 30180 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2024-05-05T23:59:54.910+02:00 INFO 30180 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-05-05T23:59:54.926+02:00 ERROR 30180 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Код: Выделить всё
spring.datasource.url=jdbc:postgresql://localhost:5432/topicusers
spring.datasource.username=postgres
spring.datasource.password=Galaxy2022
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properites.hibernate.format_sql=true
logging.level.org.springframework.web: DEBUG
logging.level.org.springframework.security=TRACE
logging.level.org.hibernate: ERROR
spring.mvc.log-request-details=true
spring.main.web-application-type= SERVLET
server.error.include-message=always
#disabling security to test posting
Проблема в том, что конфигурация работает внутри eclipse, когда я запускаю приложение, но не при запуске файла jar.
Подробнее здесь: https://stackoverflow.com/questions/784 ... e-url-erro