I have a spring boot microservice with kubernetes dependencies for configmap and secret support.The current spring boot version is 2.3.9.RELEASE . and the kubernetes dependency version is 1.1.0.RELEASE . its an old one , so i tried to update the dependency to its latest 1.1.10.RELEASE.
This is the updated pom details
<spring-cloud-kubernetes.version>1.1.10.RELEASE</spring-cloud-kubernetes.version>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-dependencies</artifactId>
<version>${spring-cloud-kubernetes.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-dependencies</artifactId>
<version>${spring-cloud-kubernetes.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
After updating the kubernetes dependency version to 1.1.10.RELEASE , am getting the below error while stating the app
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'propertyChangeWatcher' defined in class path resource [org/springframework/cloud/kubernetes/config/reload/ConfigReloadAutoConfiguration$ConfigReloadAutoConfigurationBeans.class]: Unsatisfied dependency expressed through method 'propertyChangeWatcher' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationUpdateStrategy' defined in class path resource [org/springframework/cloud/kubernetes/config/reload/ConfigReloadAutoConfiguration$ConfigReloadAutoConfigurationBeans.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.kubernetes.config.reload.ConfigurationUpdateStrategy]: Factory method 'configurationUpdateStrategy' threw exception; nested exception is java.lang.IllegalArgumentException: Restart endpoint is not enabled
This is my bootstrap.yml file
spring:
cloud:
kubernetes:
reload:
enabled: true
monitoring-config-maps: true
mode: polling
period: 15000
strategy: restart_context
config:
enabled: true
sources:
- name: demo
secrets:
enabled: true
enable-api: true
sources:
- name: demo-secret
management:
endpoint:
restart:
enabled: true
health:
enabled: true
info:
enabled: true
env:
enabled: true
refresh:
enabled: true
This is my application.yml file
management:
endpoints:
beans:
enabled: false
web:
exposure:
include: prometheus,info,refresh,health,env,restart
prometheus:
path: /api/actuator/prometheus
sensitive: false
I have enabled the restart endpoint , but still its not working . Please help me on this .
I tried the below way also , but still throwing the same issue.
<properties>
<spring.cloud-version>Hoxton.SR12</spring.cloud-version>
</properties>
<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>
Related
I am trying to expose the /actuator/health endpoint in my spring-boot application, but my log states that zero endpoints are exposed. I have seen some documentation that states that the health endpoint is the only endpoint that is enabled by default but it returns 404 for me.
Log from startup of application:
{"#timestamp":"2022-06-29T09:50:59.441+02:00","#version":1,"message":"Exposing 0 endpoint(s) beneath base path '/actuator'","logger_name":"org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver","thread_name":"main","level":"INFO","level_value":20000,"caller_class_name":"org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver","caller_method_name":"<init>","caller_file_name":"EndpointLinksResolver.java","caller_line_number":58}
Accessing /actuator also shows that no endpoints are exposed:
{"_links":{"self":{"href":"http://localhost:8000/actuator","templated":false}}}
I've looked at several other similar posts but none of the fixes provided works for me.
I do have my own endpoint as well in a #RestController that I thought might be interfering, but commenting it out its Post/Get-mappings did not help either.
My pom.xml is as follows:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath />
</parent>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
In my application.yaml I have tried the following:
server:
port: 8000
management:
health:
probes:
enabled: true
livenessstate:
enabled: true
readinessstate:
enabled: true
endpoint:
health:
probes:
enabled: true
show-details: always
enabled: true
endpoints:
web:
exposure:
include: '*'
enabled-by-default: true
Other settings in the application.yaml (like changing the port) works fine, so I know that the application.yaml is at least being used.
Any ideas?
Since spring-boot 2x these endpoints are disabled and you need to enable them. You can try adding the following to your properties:
endpoints:
enabled: false
health:
enabled: true
I also tried it via
management:
endpoint:
health:
enabled: true
but that didn't work on the platform where I deployed it (WebLogic)
here's the error:
SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [com.mycompany.chassis.engine.core.web.listener.ChassisContextLoaderListener]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'chassisApiSpringConfig': Unsatisfied dependency expressed through field 'sdpLoggingOn'; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'boolean'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value [false,false]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659)
so I upgraded to spring-beans 5.3.18, got the above error, thought I was slick and upgraded spring-core to match the version of spring-beans and I still get this error.
I have like 4 separate pom files, please direct me to how I can give you the best info to help me through this. Would upgrading spring-web to the same version help or is it something else entirely? It feels like Spring Beans doesn't recognize #Value anymore? Here's the line it's complaining about.
#Value("${sdp.logging.on:false}")
private boolean sdpLoggingOn;
Here's the imports I currently have:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Maybe Autowired and Value aren't in the factory anymore now with the upgrade?
Add the spring framework bom to your dependencyManagement section to keep all the spring framework jars at the same version.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
With multiple pom files, in my experience, it works best to have them share a common parent pom which manages the dependencies.
I'm trying to create a basic spring boot application and when I try to implement a repository i keep getting this error:
Description:
Parameter 0 of constructor in com.frana.taskme.services.RoleService required a bean named 'entityManagerFactory' that could not be found.
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
I've used all kind of Annotations in the Application.java and all kind of properties and nothing changes.
This is my repository where you can find the app: https://github.com/franagibo/test
Is there some problem with the dependencies of the pom?
Update your pom.xml jpa dependency from:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
to
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Remove from application.propertiesspring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Dont forget to update the dependencies, you might need to clean m2/repository.
you are excluding the autoconfiguration on your application.properties
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
which means you have to manually define your DataSource, SessionFactory, EntityManager ...
I am unable to get the value I am expecting, An exception is thrown at this line #Value("${message:this-is-class-value}").
SERVER SIDE
pom.xml
<dependencies>
<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.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
src/main/resources/application.properties
server.port=8888
spring.application.name=config-service
spring.cloud.config.server.git.uri=file:///C:/config
management.endpoints.web.exposure.include=*
spring.security.user.name=root
spring.security.user.password=abc123
Application class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
#SpringBootApplication
#EnableConfigServer
public class ConfigServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
Local git folder
Configurations files with the same property but the different value to detect
c:/config/application.properties
c:/config/api-gateway.properties
c:/config/api-gateway-PROD.properties
output while server startup
Completed initialization in 5 ms
WARN : Could not merge remote for master remote: null
INFO : o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/C:/config/application.properties
if I access this url
http://localhost:8888/api-gateway/PROD
console output is as follows
WARN : Could not merge remote for master remote: null
INFO : o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/C:/config/api-gateway-PROD.properties
INFO : o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/C:/config/api-gateway.properties
INFO : o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/C:/config/application.properties
CLIENT SIDE (Separate Project)
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
Application class
#SpringBootApplication
#EnableZuulProxy
#EnableDiscoveryClient
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
Controller
#RestController
public class SettingsController {
#Value("${message:this-is-class-value}")
String name = "World";
#RequestMapping("/")
public String home() {
return "Hello " + name;
}
}
resources/application.yml
server:
port: 8282
spring:
application:
name: api-gateway
eureka:
instance:
preferIpAddress: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
resources/bootstrap.yml
spring:
profiles:
active: PROD
cloud:
config:
name: api-gateway
uri: http://localhost:8888/
username: root
password: abc123
management:
endpoints:
web:
exposure:
include: refresh
Console output
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingsController': Injection of autowired dependencies failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String]
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String]
Please do let me know if anything else is required.
add message=Hello from property file1 in src/main/resources/application.properties. Or if you want to read this property from c:/config/application.properties or c:/config/config-service.properties you need to configure external configuration file by using #ConfigurationProperties annotation.
Looks, you are trying to use the #Value annotation on controller class which resides in your Cloud config server application. While the concept is like cloud config server application will be the provider to other applications and it can provide the properties from git or local file system (configuration) to requester client application. Other applications will connect to your config server application by providing it's URL, application name and profile for which it want to get the properties. You can check below URL for cloud config server and client application.
https://www.thetechnojournals.com/2019/10/spring-cloud-config.html
Your cloud config server has security configuration as below.
spring.security.user.name=root
spring.security.user.password=abc123
You client configuration doesn't provide any security configuration which is causing 401 error in your logs.
To solve this issue please do below changes to your client configuration.
Client configuration:
spring:
profiles:
active: PROD
cloud:
config:
name: api-gateway
uri: http://localhost:8888/
username: root
password: abc123
I have a spring boot project,It run just fine when I execute via eclipse Project > Run as > spring boot app
but when I build the project and execute it using java -jar myproject.jar or run it using mvn spring-boot:run it throw this error
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: com.microsoft.sqlserver.jdbc.SQLServerDriver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class com.microsoft.sqlserver.jdbc
.SQLServerDriver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
my sql server connector dependency
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
<scope>test</scope>
</dependency>
and here my application.properties
spring.datasource.url=jdbc:sqlserver://mydb;databaseName=HTSdb
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
it looks my app can't find the sqlserver driver but it is already in project classpath,any suggestion? thanks in advance
I think the issue is with dependency scope which is set as test.
Scope test indicates that dependency isn't required at standard runtime of application and should only be used for purpose of test runs only!
Usually database connectors dependency are set with runtime scope.
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
<scope>runtime</scope>
</dependency>
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driver-class-name
Value: org.postgresql.Driver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class org.postgresql.Driver in either of HikariConfig
class loader or Thread context classloader
Action:
Update your application's configuration
Just had the same error, in my case with "org.postgresql.Driver".
Gues what was the issue? an empty space after "org.postgresql.Driver " by mistake.
So, be aware about that ' ' invisible empty space :).
Add dependency
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
check if Jar is loaded in lib if not then you need to add version 8.2.1.jre8 and rebuild the project .
You can validate by checking if mssql-jdbc-8.2.1.jre8 jar is there loaded in project and it has SQLServerDriver.class file in it .