Config Client is not working in Spring boot
I was trying out config server client in Spring boot and came across this weird issue.
I have been able to successfully spin up the config server up and running but while trying to start the config client/consumer, it seems like the client isn't fetching any information from the config server.
Output while running client:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.1)
2020-12-24 02:01:28.717 INFO 3000 --- [ main] c.r.service.profile.ProfileApplication : Starting ProfileApplication using Java 1.8.0_121 on DESKTOP-RID7KR with PID 3000 (E:\Spring\rent-a-car\profile\target\classes started by Dawg in E:\Spring\rent-a-car\profile)
2020-12-24 02:01:28.727 INFO 3000 --- [ main] c.r.service.profile.ProfileApplication : No active profile set, falling back to default profiles: default
2020-12-24 02:01:30.161 INFO 3000 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-12-24 02:01:30.263 INFO 3000 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 82 ms. Found 1 JPA repository interfaces.
2020-12-24 02:01:30.642 INFO 3000 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=99ce795d-c5e8-3f6e-87d9-3efbe096b86a
2020-12-24 02:01:32.012 INFO 3000 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-12-24 02:01:32.027 INFO 3000 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-12-24 02:01:32.027 INFO 3000 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2020-12-24 02:01:32.287 INFO 3000 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-12-24 02:01:32.287 INFO 3000 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3430 ms
2020-12-24 02:01:32.431 WARN 3000 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.autoconfigure.RefreshAutoConfiguration$JpaInvokerConfiguration': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; 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
2020-12-24 02:01:32.444 INFO 3000 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-12-24 02:01:32.478 INFO 3000 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-12-24 02:01:32.513 ERROR 3000 --- [ 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).
Process finished with exit code 1
bootstrap.yml (config-client)
spring:
application:
name: profile
profiles:
active: prod
cloud:
config:
name: profile
uri: http://localhost:8181
Have not included any application.yml file for config-client.
My config server is up on port 8181 and i am able to fetch the config from github successfully,
Sample success response:
{
"name":"profile",
"profiles":[
"prod"
],
"label":null,
"version":"24275f56bf516d847f171c9fc419ddef141bd39b",
"state":null,
"propertySources":[
{
"name":"https://github.com/vishu221b/rentaca-config-store.git/file:C:\\Users\\Vishal\\AppData\\Local\\Temp\\config-repo-2331899650646506\\service-config\\profile-service\\profile-prod.yml",
"source":{
"server.port":8081
}
},
{
"name":"https://github.com/vishu221b/rentaca-config-store.git/file:C:\\Users\\Vishal\\AppData\\Local\\Temp\\config-repo-2331899650646506\\application.yml",
"source":{
"spring.datasource.url":"jdbc:postgresql://127.0.0.1:5432/rent-a-car?createDatabaseIfNotExist=true",
"spring.datasource.username":"cofix",
"spring.datasource.password":"C0fiX",
"spring.datasource.driver-class-name":"org.postgresql.Driver",
"spring.jpa.hibernate.naming.physical-strategy":"org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl",
"spring.jpa.properties.hibernate.dialect":"org.hibernate.dialect.PostgreSQLDialect"
}
}
]
}
I know there must be some key/value errors in the files above, i'll manage that but only given that my config-client starts fetching config from my config-server running successfully.
There is no security in my config-server so i won't need username, password.
pom.xml (config-client)
<?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.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.reantacar.service</groupId>
<artifactId>profile</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>profile</name>
<description>Profile service for Rent A Car application.</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-config -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- <!–The jar needs to be imported to make the bootstrap.yml configuration file take effect –>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-context</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.rentacar.commons</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>
PS: I have tried debugging this a lot over other stackoverflow questions and official docs on internet, but nothing seems to be fixing my issue. Initially i thought that my bootstrap.yml file must not be loading for some reasons, but now i am feeling that the config isn't working for my client at all because in the startup log it is mentioned that configuration from specific config-server-name/link:port was being tried to be fetched.
Also, please ignore the errors in my grammar :)
2020.0.0 Spring Cloud Config does not support bootstrap file.
For a workaround use bootstrap.{yml|properties} and add a dependency on
spring-cloud-starter-bootstrap to restore the old behavior.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
More information:
https://github.com/spring-cloud/spring-cloud-release/wiki/Spring-Cloud-2020.0-Release-Notes#breaking-changes
However, this was working before, but now and as mentioned above you have to your client project
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
spring-boot ver=2.4.3
spring-cloud ver=2020.0.1
Also, you can set the below property in your bootstrap. properties to make the client project fails to startup if fails to connect to the config server:
spring.cloud.config.fail-fast=true
To resolve this problem in Spring Cloud Config
If you are using a 2.4.0 or greater version of spring boot and
If you are using the 2020.0.0 or greater version of spring-cloud.
you need to add this dependency to the pom.xml (spring-cloud-config-client)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
Example of my pom.xml (spring-cloud-config-client)
<?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.7.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>pay-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>pay-service</name>
<description>Pay project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<spring-cloud.version>2021.0.5</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Try like this, I hope it will work
Sometimes, it happen because you added the 'config client of spring cloud config' dependency, it required configuration in application.properties, add the configuration of your config server so you see the example below
src/main/resources/application.properties
server.port=8100
spring.config.import=optional:configserver:http://localhost:8888
Note: SNAPSHOT, M1, M2, M3, and M4 releases typically WORK IN PROGRESS. The Spring team is still working on them, Recommend NOT using them.
Related
so recently i thought of upgrading few dependency of my spring boot project project
specifically these components
jakarat ee 9
spring boot 2.7
hibernate 6.0.2.Final
after doing this all updates and code refraction: updating imports javax to jakarta, and for few hibernate annotations
I removed the old hibernate from my local .m2 repository and run this command this mvn clean install test package
and started the project in intellij and it gave be below error:
16:15:42.410 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader#429054cc
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.0)
2022-05-30 16:15:42.787 INFO 99522 --- [ restartedMain] com.zee.oms.order.Order : Starting Order using Java 17.0.2 on ZL-BLR-MAC170.local with PID 99522 (/Users/manish.prasad/Documents/ZEE-Services/github/zee5-order/target/classes started by manish.prasad in /Users/manish.prasad/Documents/ZEE-Services/github/zee5-order)
2022-05-30 16:15:42.787 DEBUG 99522 --- [ restartedMain] com.zee.oms.order.Order : Running with Spring Boot v2.7.0, Spring v5.3.20
2022-05-30 16:15:42.787 INFO 99522 --- [ restartedMain] com.zee.oms.order.Order : No active profile set, falling back to 1 default profile: "default"
2022-05-30 16:15:42.818 INFO 99522 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-05-30 16:15:42.818 INFO 99522 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-05-30 16:15:43.347 INFO 99522 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-05-30 16:15:43.433 INFO 99522 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 81 ms. Found 4 JPA repository interfaces.
2022-05-30 16:15:43.862 INFO 99522 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-05-30 16:15:43.868 INFO 99522 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-05-30 16:15:43.868 INFO 99522 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.63]
2022-05-30 16:15:43.902 INFO 99522 --- [ restartedMain] o.a.c.c.C.[.[localhost].[/order-srv] : Initializing Spring embedded WebApplicationContext
2022-05-30 16:15:43.902 INFO 99522 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1084 ms
2022-05-30 16:15:44.059 WARN 99522 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderController': Unsatisfied dependency expressed through field 'orderService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderServiceImpl': Unsatisfied dependency expressed through field 'orderRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderRepository' defined in com.zee.oms.order.repository.OrderRepository defined in #EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot create inner bean '(inner bean)#14203bc' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#14203bc': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2022-05-30 16:15:44.061 INFO 99522 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-05-30 16:15:44.072 INFO 99522 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-30 16:15:44.080 ERROR 99522 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field orderRepository in com.oms.order.service.impl.OrderServiceImpl required a bean named 'entityManagerFactory' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
Process finished with exit code 0
this is my pom:
<?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
http://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.7.0</version>
<relativePath/>
</parent>
<groupId>com.zee</groupId>
<artifactId>zee5-order</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>order</name>
<description>Spring Boot project for order-service</description>
<properties>
<java.version>17</java.version>
<hibernate.version>6.0.2.Final</hibernate.version>
</properties>
<dependencies>
<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>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.4.Final</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webmvc-core</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webflux-ui</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>8.5.10</version>
</dependency>
<dependency>
<groupId>com.common-utility</groupId>
<artifactId>common-utility</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>1.12.220</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.212</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-60</artifactId>
<version>2.16.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
attaching few screen shots for the added dependencies:
spring and spring boot dependencies
jakarta dependencies
any idea or solution if anybody have also upgraded to this version and able to run the project successfully.
also iam confused why javax-persistence is still there and not replaced when jakarata-persistence is already added/there.
Hibernate 6 (and Hibernate Validator 7 as well) are JakartaEE implementations of respectivly the Jakarta Persistence API and Jakarta Validation API. None of which are currently supported by Spring nor Spring Boot.
Support for JakartaEE is coming in Spring Framework 6 and Spring Boot 3 which are scheduled for release later this year.
For now keep using the JavaEE versions. In your case you need to do 2 things
Remove the hibernate.version property
Replace the hibernate-validator and jakarta-validation-api with the spring-boot-starter-validation dependency.
When you apply both fixes and later this year upgrade to Spring Boot 3 you will get the proper versions which are compatible.
I am getting following error in console :
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-10-09 19:17:13.032 INFO 2692 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-10-09 19:17:13.065 INFO 2692 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-09 19:17:13.073 ERROR 2692 --- [ 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).
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.2.10.RELEASE</version>
<relativePath />
<!-- lookup parent from repository -->
</parent>
<groupId>com.merchant</groupId>
<artifactId>merchantconfiguration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>merchantconfiguration</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.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.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties :
spring.datasource.url=jdbc:postgresql://localhost:5432/hitachipyg_db
spring.datasource.username=postgres
spring.datasource.password=hitachi#123
spring.jpa.show.sql=true
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto= update spring.datasource.driver-class-name=org.postgresql.Driver
Could you please try the below property in you application.properties file.
spring.datasource.driver-class-name=org.postgresql.Driver
Not able to run spring boot application
Tried removing contents of /C:/Users/SaurKumar/.m2/repository/org/springframework/data/spring-data-commons/2.1.10.RELEASE/spring-data-commons-2.1.10.RELEASE.jar
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-08 05:22:05.217 INFO 2420 --- [ main] i.j.c.CourseApiDataApplication : Starting CourseApiDataApplication on BLRLW8166 with PID 2420 (C:\Users\SaurKumar\Downloads\course-api-data\course-api-data\target\classes started by saurkumar in C:\Users\SaurKumar\Downloads\course-api-data\course-api-data)
2019-09-08 05:22:05.222 INFO 2420 --- [ main] i.j.c.CourseApiDataApplication : No active profile set, falling back to default profiles: default
2019-09-08 05:22:06.110 INFO 2420 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-09-08 05:22:06.215 ERROR 2420 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.postProcess(JpaRepositoryConfigExtension.java:121)
The following method did not exist:
org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/lang/String;
The method's class, org.springframework.data.repository.config.RepositoryConfigurationSource, is available from the following locations:
jar:file:/C:/Users/SaurKumar/.m2/repository/org/springframework/data/spring-data-commons/2.1.10.RELEASE/spring-data-commons-2.1.10.RELEASE.jar!/org/springframework/data/repository/config/RepositoryConfigurationSource.class
It was loaded from the following location:
file:/C:/Users/SaurKumar/.m2/repository/org/springframework/data/spring-data-commons/2.1.10.RELEASE/spring-data-commons-2.1.10.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.RepositoryConfigurationSource
Process finished with exit code 1
-----------------------------------------
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.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.javabrains</groupId>
<artifactId>course-api-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>course-api-data</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
From the logs, it seems Spring is picking a different version for groupId org.springframework.data than the one provided with spring-data-jpa. If you could match the versions of spring-boot-starter-web and spring-data-jpa, it should work.
Quick fix being: Remove the version number for spring-data-jpa and it will by default take the latest version, which in your case is 2.1.10.RELEASE.
I'm so new in Linux and I'm trying to run my Spring boot application with embedded tomcat on it I tried literally everything on the internet but I can't understand my problem. So this is my code (Maven)
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test.my.app</groupId>
<artifactId>TestApplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<start-class>com.test.my.Applocation.App</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
and this is my application.properties file.
server.port=0
and this is how I build my project to Jar :
mvn -> clean -> compile -> package
and I can run this application on my Windows computer and its working just fine! but my problem is in the Linux server when I run this application with systemed this is the log and it says it was successful but it's not working
INFO 20351 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$b190a49] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO 20351 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 0 (http)
INFO 20351 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
INFO 20351 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
INFO 20351 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
INFO 20351 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
INFO 20351 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2302 ms
INFO 20351 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
INFO 20351 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 41940 (http) with context path ''
INFO 20351 --- [ main] c.t.c.TransApplication.TransApplication : Started TransApplication in 4.878 seconds (JVM running for 5.402)
and this is my
netstat -ltnpa | grep -i --colour LISTEN
log from 41940 port
tcp6 0 0 :::41940 :::* LISTEN 20351/java
but now i want to send a request to this port with example.com:41940/myrequest but its not working and server is not respondig
===================
EDIT
i edit the server.port=0 to 8090
and this is the result of
curl -XGET localhost:8090
curl -XGET localhost:8090 % Total % Received % Xferd Average
Speed Time Time Time Current
Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:--
--:--:-- 0100 93 0 93 0 0 325 0 --:--:-- --:--:-- --:--:-- 326 { "_links" : {
"profile" : {
"href" : "http://localhost:8090/profile"
} } }
Try to start your application with this parameters:
-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses
And then with netstat make sure that the application is listening on IPv4.
If it is also not working post the output of this:
curl -sSL -D - http://localhost:8090 -o /dev/null
Have a look here: Spring boot application listens over IPv6 without -Djava.net.preferIPv4Stack=true and -Djava.net.preferIPv4Addresses parameters
I think your tomcat only listens on IPv6 not IPv4.
BR
as I said I'm so new in Linux And the problem was that I did not introduce the port to the firewall and now working
I am deploying my Spring Boot application to a Pivotal Cloud Foundation container.
I got the same error but found I was missing a POM dependency (and it appears you are too):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
I found this in Post:
Spring boot: Unable to start embedded Tomcat servlet container
NOTE, it has led to different error for me, but I made progress.
Conclusion of my matter for posterity ...
I add this comment because this is what fixed my problem.
The Dependency was pulling in Servlet API 2.5
Tomcat 8.5 (embedded Spring Boot) needs Servlet API 3.1!
<groupId>org.jvnet.jax-ws-commons.spring</groupId>
<artifactId>jaxws-spring</artifactId>
<version>1.9</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
Dependency had Servlet 2.5 API.
Tomcat 8.1 needs '3.1'
found to looking at Maven dependency tree:
man dependency:tree
From this post: Getting NoSuchMethodError:javax.servlet.ServletContext.getVirtualServerName()
I have a spring boot rest web application which works perfectly on the embedded server. However after following the steps mentioned in the is blog https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file, I got a 404 error message whan I send a resquest to a resource on the server.I have used java 1.8.0_212 locally and used java 1.8.0_131 and deployed my app on tomcat 9 on the server. One thing that's puzzling me is that the repositories which extends CrudRepository can be accessed. Below is my application's entry point.
#SpringBootApplication
#ComponentScan(basePackages = "com.dbe.ref")
public class RefmsApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(RefmsApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(RefmsApplication.class, args);
}
and also my 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dbe.ref</groupId>
<artifactId>refms</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>refms</name>
<description>project for Rural electrification fund</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>LATEST</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<start-class>com.RefmsApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>angularjs</artifactId>
<version>1.4.10</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>4.7.0</version>
</dependency>
<dependency>
<groupId>eu.michael-simons</groupId>
<artifactId>wro4j-spring-boot-starter</artifactId>
<version>0.3.4</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>net.sourceforge.dynamicreports</groupId>
<artifactId>dynamicreports-core</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
<build>
<finalName>refms</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here is part of the log:
2017-09-19 10:38:20.564 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*]
2017-09-19 10:38:20.565 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-09-19 10:38:20.566 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-09-19 10:38:20.568 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-09-19 10:38:20.568 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-09-19 10:38:20.571 INFO 6660 --- [ main] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2017-09-19 10:38:20.571 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'configurableWroFilter' to urls: [/wro4j/*]
2017-09-19 10:38:20.572 INFO 6660 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServletRegistration' to [/refms/*]
2017-09-19 10:38:20.573 INFO 6660 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
There is a little difference when you deploy application on embedded server and external server by default.
With embedded server you can access you application by using:
http://localhost:<port>/<resourceName>
While if you deploy war in another container then you need to add application name with version like:
http://localhost:<port>/<applicationNameWithVersion>/<resourceName>
For example if you deploy this example then URL for embedded server is:
http://localhost:8080/greeting
And URL for Externally deployed application if like:
http://localhost:8999/gs-rest-service-0.1.0/greeting
Note: This URL is of my application server so it may have some changes for yours.
Comment if you need help.
Check if the
<build>
<finalName>refms</finalName>
...
</build>
in the pom.xml corresponds with the
server.contextPath=/refms
in the application.properties and check the
<Context path="/refms"/>
in the context.xml. Perhaps your root context in tomcat
after deploy was different.
Additionally, change this dependence
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
by this
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
for external tomcat
Check the root package in src/main/java, it should be the same as the package name mentioned in the POM groupid ie. com.dbe.ref if there is any mismatch than the same issue occurs.
Make sure you have added context path to your spring Boot application. Typically it is in application.properties file inside src\main\resources. In that properties file, add the properties:
server.contextPath=/refms
You should be able to access your application using the bellow link
localhost:8080/refms/api/account/authenticate or localhost:8080/refms-xxxx/api/account/authenticate ( where xxxx is your artifact version )
in your comments you mentioned /authenticate is giving 404, this is because you have set the login process URL to “authenticate”. It’s the URL that the login form is posted to. If unspecified, it defaults to /login.
Spring Security framework intercepts that URL and gets login and password parameter.
When you deploy your application into Tomcat the URL depends on the context path under which your application gets deployed. Most of the time this is an exact match with the name of the war file which you put into the Tomcat 'webapps' directory. You can see the name by looking at your 'webapps' directory. Your war file is probably also expended into a directory by now.
Since you've put a finalName into your maven build section, your war file should be named: refms.war, so your application will run under:
http://host:port/refms/
My assumption is that you did not rename the war file to ROOT.war before you copied it into tomcat, so your application will not be running on:
http://host:port/
If you would do so your application will run similar to the embedded Tomcat instance; on the root context.
From your log file I can see that your authentication endpoint is mapped on /refms/
Mapping servlet: 'dispatcherServletRegistration' to [/refms/*]
This is relative to the context root of your application.
So in case you did not rename your war file, the authentication endpoint on which you receive a 404 is probably going to be under:
http://localhost:8080/refms/refms/api/account/authenticate