#java #spring #postgresql #eclipse #jpa
Вопрос:
Вчера я мог запустить свое приложение, подключить его к базе данных и даже использовать его, сегодня я просто не могу. Я использую springboot, eclipse, swagger и postgresql. Уже пытался перезапустить postgresql на моей машине, и ничего.
Сообщение об ошибке:
10:04:58.744 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@7708de08 . ____ _ __ _ _ /\ / ___'_ __ _ _(_)_ __ __ _ ( ( )___ | '_ | '_| | '_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.6.1) 2021-12-03 10:04:59.003 INFO 4672 --- [ restartedMain] com.crud.CrudApplication : Starting CrudApplication using Java 17.0.1 on GON170102162 with PID 4672 (C:Usersmurillo.jorgeeclipse-workspaceCRUDtargetclasses started by murillo.jorge in C:Usersmurillo.jorgeeclipse-workspaceCRUD) 2021-12-03 10:04:59.004 INFO 4672 --- [ restartedMain] com.crud.CrudApplication : No active profile set, falling back to default profiles: default 2021-12-03 10:04:59.037 INFO 4672 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2021-12-03 10:04:59.037 INFO 4672 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 2021-12-03 10:04:59.595 INFO 4672 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2021-12-03 10:04:59.627 INFO 4672 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 27 ms. Found 1 JPA repository interfaces. 2021-12-03 10:05:00.011 INFO 4672 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2021-12-03 10:05:00.020 INFO 4672 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2021-12-03 10:05:00.020 INFO 4672 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.55] 2021-12-03 10:05:00.102 INFO 4672 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2021-12-03 10:05:00.103 INFO 4672 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1065 ms 2021-12-03 10:05:00.144 WARN 4672 --- [ restartedMain] 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; 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 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class 2021-12-03 10:05:00.146 INFO 4672 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2021-12-03 10:05:00.157 INFO 4672 --- [ restartedMain] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-12-03 10:05:00.168 ERROR 4672 --- [ restartedMain] 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).
Мой pom.xml
lt;?xml version="1.0" encoding="UTF-8"?gt; lt;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"gt; lt;modelVersiongt;4.0.0lt;/modelVersiongt; lt;parentgt; lt;groupIdgt;org.springframework.bootlt;/groupIdgt; lt;artifactIdgt;spring-boot-starter-parentlt;/artifactIdgt; lt;versiongt;2.6.1lt;/versiongt; lt;relativePath/gt; lt;!-- lookup parent from repository --gt; lt;/parentgt; lt;groupIdgt;com.examplelt;/groupIdgt; lt;artifactIdgt;demolt;/artifactIdgt; lt;versiongt;0.0.1-SNAPSHOTlt;/versiongt; lt;namegt;demolt;/namegt; lt;descriptiongt;Demo project for Spring Bootlt;/descriptiongt; lt;propertiesgt; lt;java.versiongt;1.8lt;/java.versiongt; lt;/propertiesgt; lt;dependenciesgt; lt;dependencygt; lt;groupIdgt;org.springframework.bootlt;/groupIdgt; lt;artifactIdgt;spring-boot-starter-data-jpalt;/artifactIdgt; lt;/dependencygt; lt;dependencygt; lt;groupIdgt;org.springframework.bootlt;/groupIdgt; lt;artifactIdgt;spring-boot-starter-weblt;/artifactIdgt; lt;/dependencygt; lt;dependencygt; lt;groupIdgt;org.springframework.bootlt;/groupIdgt; lt;artifactIdgt;spring-boot-devtoolslt;/artifactIdgt; lt;scopegt;runtimelt;/scopegt; lt;optionalgt;truelt;/optionalgt; lt;/dependencygt; lt;dependencygt; lt;groupIdgt;org.postgresqllt;/groupIdgt; lt;artifactIdgt;postgresqllt;/artifactIdgt; lt;scopegt;runtimelt;/scopegt; lt;/dependencygt; lt;dependencygt; lt;groupIdgt;org.projectlomboklt;/groupIdgt; lt;artifactIdgt;lomboklt;/artifactIdgt; lt;optionalgt;truelt;/optionalgt; lt;/dependencygt; lt;dependencygt; lt;groupIdgt;org.springframework.bootlt;/groupIdgt; lt;artifactIdgt;spring-boot-starter-testlt;/artifactIdgt; lt;scopegt;testlt;/scopegt; lt;/dependencygt; lt;dependencygt; lt;groupIdgt;io.springfoxlt;/groupIdgt; lt;artifactIdgt;springfox-swagger2lt;/artifactIdgt; lt;versiongt;3.0.0lt;/versiongt; lt;/dependencygt; lt;dependencygt; lt;groupIdgt;io.springfoxlt;/groupIdgt; lt;artifactIdgt;springfox-boot-starterlt;/artifactIdgt; lt;versiongt;3.0.0lt;/versiongt; lt;/dependencygt; lt;dependencygt; lt;groupIdgt;io.springfoxlt;/groupIdgt; lt;artifactIdgt;springfox-swagger-uilt;/artifactIdgt; lt;versiongt;3.0.0lt;/versiongt; lt;/dependencygt; lt;/dependenciesgt; lt;buildgt; lt;pluginsgt; lt;plugingt; lt;groupIdgt;org.springframework.bootlt;/groupIdgt; lt;artifactIdgt;spring-boot-maven-pluginlt;/artifactIdgt; lt;configurationgt; lt;excludesgt; lt;excludegt; lt;groupIdgt;org.projectlomboklt;/groupIdgt; lt;artifactIdgt;lomboklt;/artifactIdgt; lt;/excludegt; lt;/excludesgt; lt;/configurationgt; lt;/plugingt; lt;/pluginsgt; lt;/buildgt; lt;/projectgt;
my application properties
spring.datasource.url=jdbc:postgresql://localhost:5432/Clientes spring.datasource.username=admin spring.datasource.password=admin spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.show_sql=true spring.jpa.properties.hibernate.format_sql=true #spring.datasource.url=${JDBC_DATASOURCE_URL} #spring.jpa.show-sql=true #spring.jpa.generate-ddl=true spring.mvc.pathmatch.matching-strategy=ant-path-matcher
Структура моего проекта
| .classpath | .gitignore | .project | HELP.md | mvnw | mvnw.cmd | pom.xml | test.txt | ---.mvn | ---wrapper | maven-wrapper.jar | maven-wrapper.properties | MavenWrapperDownloader.java | ---.settings | org.eclipse.core.resources.prefs | org.eclipse.jdt.core.prefs | org.eclipse.m2e.core.prefs | org.springframework.ide.eclipse.prefs | ---src | ---main | | ---java | | | ---com | | | ---crud | | | | CrudApplication.java | | | | | | | ---controller | | | | ClienteController.java | | | | | | | ---model | | | | Cliente.java | | | | | | | ---repository | | | ClienteRepository.java | | | | | ---resources | | | application.properties | | | | | ---static | | ---templates | ---test | ---java | ---com | ---crud | CrudApplicationTests.java | ---target ---classes | | application.properties | | | ---com | ---crud | | CrudApplication.class | | | ---controller | | ClienteController.class | | | ---model | | Cliente.class | | | ---repository | ClienteRepository.class | ---test-classes ---com ---crud CrudApplicationTests.class
Изменить: поместите структуру моего проекта и сообщение об ошибке в теги кода
Комментарии:
1. пожалуйста, добавьте ведение журнала как есть с кодовыми тегами, а не в кавычках, так как сейчас оно совершенно нечитабельно. Ваш
application.properties
, вероятно, находится в неправильном месте, следовательно, не читается, отсюда и ошибка.2. Он находится внутри src/main/ресурсов
3. Еще раз, пожалуйста, добавьте ведение журнала как есть, текущее полностью нечитабельно (и невозможно исправить, я предпринял попытку переформатирования, но это невозможно). Также покажите структуру вашего проекта. Должно быть, что-то мешает его прочитать.
4. Просто добавил мое сообщение об ошибке в теги кода и разместил структуру моего проекта в моем исходном сообщении.
5. Попробуйте mvn spring-boot:запустите и посмотрите, что произойдет