Spring Boot Cloud Hystrix - spring

I am getting "error creating bean with name hystrixstreamendpoint" defined in classpath resource [org/springframework.cloud/netflix/hystrix/Hystrixcircuitbreakerconfiguaration$HystrixWebconfiguaration.class] : invocation of init method failed:
Spring boot maven is
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.12.RELEASE</version>
</dependency>
and Hystrix maven is
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.7.RELEASE</version>
Please help me out. I have been stuck here from last 2 days.

Related

Upgrading Spring Boot to 2.5.9 and getting FileNotFoundException: class path ...../boot/actuate/health/HealthAggregator.class] cannot be opened

I am getting a FileNotFoundException during Spring Boot initiation for org/springframework/boot/actuate/health/HealthAggregator.class. This seem related to https://github.com/spring-projects/spring-boot/issues/19860 but that was back in 2.2.
I have tried different versions of Spring Boot, 2.5.9 etc, different versions of Spring Cloud, etc.
Any thoughts on how I can resolved this?
Key parts of my POM
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
..
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
..
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
..
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-client-config</artifactId>
<version>2.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
The error:
is 2022-01-25 20:16:20 WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.xxxxx.vms.yyyyy]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/actuate/health/HealthAggregator.class] cannot be opened because it does not exist 2022-01-25 20:16:20 ERROR o.s.boot.SpringApplication - Application run failed

Error Deploying Spring Boot App using 2.6.2 on IBM Websphere 8.5.5.20

I'm trying to Deploying a spring boot app using 2.6.2 on IBM Websphere 8.5.5.20 (Using java 8)
To test out the Issue I have tried to deploy a simple Hello World restcontroller and facing the issues noted below. I'm able to deploy the application using Spring Boot 1.5 on Websphere 8.5.5.20, but facing difficulty when moving to spring-boot 2.6.2.
Please note I have tried with the javax.servlet and jakarta.servlet (version as per spring boot dependencies). I have followed this Link [https://stackoverflow.com/questions/48156126/websphere-8-5-with-spring-5], Deploy Spring Boot 2.x apps on WebSphere 8.5.5
I get the following error based on how I have the classloader for my app by setting it from
Enterprise Applications > simple-boot > Manage Modules > simple-boot.war
Parent Last
Error:
[1/7/22 16:39:57:407 EST] 00000001 ContainerHelp E WSVR0501E: Error creating component com.ibm.ws.runtime.component.CompositionUnitMgrImpl#c412fa58
com.ibm.ws.exception.RuntimeWarning: com.ibm.ws.exception.RuntimeWarning: com.ibm.ws.webcontainer.exception.WebAppNotLoadedException: Failed to load webapp: Failed to load webapp: javax.servlet.ServletContainerInitializer: Provider ch.qos.logback.classic.servlet.LogbackServletContainerInitializer not a subtype
Parent First
Error:
[1/7/22 16:42:17:173 EST] 00000047 SystemOut O 2022-01-07 16:42:17.173 WARN 31546 --- [ver.startup : 1] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax/validation/Configuration.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider; (loaded from file:/xxxxxxx/was/INSTANCE1/plugins/javax.j2ee.validation.jar by org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader#25be5b0d) called from class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean (loaded from file:xxxx/simple-boot.ear/simple-boot.war/WEB-INF/lib/spring-context-5.3.14.jar by
com.ibm.ws.classloader.CompoundClassLoader#24768f5e[war:simple-boot/simple-boot.war]
My pom.xml
Note: In this pom.xml I have javax.servlet using 3.1.0 for testing but as noted above tried with default version as per the spring boot dependencies also with same result.
<?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.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.my.testApp</groupId>
<artifactId>simple-webapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>simple-boot</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>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<exclusions>
<exclusion>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
<build>
<finalName>simple-boot</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Based on the error message, the parent-last version looks like it's failing because there is a copy of the Servlet API packaged in your application. This is not a usable configuration, because the container will link to its own copy of the API, and as a result it wouldn't be able to successfully cast application artifacts that link to their own API instance. There are some APIs for which you can bring your own version in the app, but Servlet is not among them.
For the parent-first failure, it looks like Spring is expecting a newer version of the javax.validation package than is provided by the server - it's calling a method that doesn't exist in the server's version. WebSphere 8.5.5 implements Java EE 6, which includes Bean Validation 1.0, and that method wasn't added until Bean Validation 1.1. You'll need a version of Spring that works with Java EE 6 or is configurable to avoid higher-version dependencies. It might also be possible to resolve this by running parent-last and including a separate implementation along with the API (obviously, removing the Servlet API as referenced in the previous paragraph), although I'm not familiar enough with the Bean Validation API to know whether that would cause a conflict with the server runtime in the same way as Servlet.

Problem extending Spring WebFlux application with reactive DB client: conflicting Maven dependencies?

I have a small working Spring WebFlux app made basing on this code:
https://github.com/chang-chao/spring-webflux-reactive-jdbc-sample
As far as I've understood this is some kind of mix between purely reactive programming and usual blocking relational databases.
Now I have a task to add reactive DB client to my app. I stared with this guide:
https://spring.io/guides/gs/accessing-data-r2dbc/
But as soon as I added following dependencies to my pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-h2</artifactId>
<version>0.8.4.RELEASE</version>
<scope>runtime</scope>
</dependency>
my WORKING app failed to start saying it couldn't find autowired repository bean. This error disappeared as soon as I've removed two dependencies above.
Initial full pom.xml of WORKING app:
<?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.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.freelance</groupId>
<artifactId>studentlist</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>student-list</name>
<description>Spring WebFlux application for managing students</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.3.4.RELEASE</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.3.10.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I suppose some dependencies are conflicting with each other. Is there a way to actually use these dependencies with all my other dependencies so I'll be able to follow that guide?
I don't know if app's Java code is needed for this question, and if it is, which pieces. For now I'll just add application.properties:
spring.h2.console.enabled=true
spring.h2.console.path=/h2_console
spring.datasource.url=jdbc:h2:~/studentlist
spring.datasource.platform=h2
spring.datasource.initialization-mode=always
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.generate-ddl=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql=true
logging.level.org.springframework=warn
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=trace
logging.level.org.hibernate.SQL=warn
logging.level.io.netty=warn
spring.datasource.maximum-pool-size=100
Adding either of these two dependencies, spring-boot-starter-data-r2dbc or r2dbc-h2, without the second one is enough to cause this error:
2020-10-20 15:31:26.008 WARN 11580 --- [ main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'studentService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentService': Unsatisfied dependency expressed through field 'studentRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.freelance.studentlist.repository.StudentRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
2020-10-20 15:31:26.123 ERROR 11580 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field studentRepository in com.freelance.studentlist.service.StudentServiceImpl required a bean of type 'com.freelance.studentlist.repository.StudentRepository' 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 of type 'com.freelance.studentlist.repository.StudentRepository' in your configuration.
Process finished with exit code 1
I removed JPA dependency and I'm currently trying to make things work with just r2dbc.
I suppose my application.properties would no longer be valid. Could you please help me with changing it? I use this code fragment from the guide:
public class R2DBCConfiguration extends AbstractR2dbcConfiguration {
#Bean
public H2ConnectionFactory connectionFactory() {
return new H2ConnectionFactory(
H2ConnectionConfiguration.builder()
.url("jdbc:h2:~/studentlist;DB_CLOSE_DELAY=-1;TRACE_LEVEL_FILE=4")
.username("sa")
.build());
}
}
I strongly suspect that such url is not valid for r2dbc. What would be valid substitution for jdbc:h2:~/studentlist URL in case of r2dbc H2 (not in-memory, just local DB)?
How should I change this block of code in application.properties ? URL in particular!
**spring.datasource.url=jdbc:h2:~/studentlist**
spring.datasource.platform=h2
spring.datasource.initialization-mode=always
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
Please help if you know! Can't google an appropriate example for now...
The spring.datasource is for the traditional Jdbc data source, to configure an R2dbc connection, use spring.r2dbc prefix instead in Spring Boot application.properties.
Check my Spring R2dbc example, if you are new to Spring Data R2dbc, the docs in Readme.md.

Zipkin with Spring Boot 2.2 and Hoxton Cloud

I wanted to update my project Zipkin setup to Spring Boot 2.2.2.RELEASE and Spring Cloud Hoxton.RELEASE but it looks like simple jars update is not enough.
I thought the old setup (it was working fine for Spring Boot 2.1.5.RELEASE and Greenwich.SR2) would also work for Boot 2.2.2.RELEASE and Hoxton.RELEASE but it appears I still miss something here.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
...
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
<!-- <zipkin.version>2.12.9</zipkin.version> does not work either-->
<zipkin.version>2.11.8</zipkin.version>
...
</properties>
<dependencies>
<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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>${zipkin.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>${zipkin.version}</version>
<scope>runtime</scope>
</dependency>
...
</dependencies>
I'm getting the following exception (java.lang.NoClassDefFoundError: zipkin2
/internal/Buffer$Writer):
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/We
bMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pr
ometheusMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: Initialization of bean failed; nested exception is or
g.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'zipkin2.server.internal.ZipkinServerConfiguration': Unsatisfied dependency expressed through field 'httpQuery'; nested exception is org
.springframework.beans.factory.BeanCreationException: Error creating bean with name 'zipkin2.server.internal.ZipkinQueryApiV2': Bean instantiation via constructor failed; nested exception is java.lang.NoClassDefFoundError: zipkin2
/internal/Buffer$Writer
It's a version problem. Zipkin officially recommends use zipkin-server instate of customer server after spring-boot 2.x.
For me, the 2.12.9 library works well under spring-boot 2.1.8.RELEASE with spring-cloud Greenwich.SR6

ClassNotFoundException with Spring WebFlux Security

I'm having the following problem:
I am trying to setup a basic Spring Boot (2.0.0.M2) Project containing Spring Webflux and Spring Security.
My pom.xml looks like this (generated via start.spring.io):
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
...
</dependencies>
SpringSecurityConfig:
#EnableWebFluxSecurity
public class SecurityConfig extends WebFluxSecurityConfiguration {}
I am not getting any further because I get an exception on startup:
Caused by: java.lang.ClassNotFoundException: org.springframework.security.web.server.context.SecurityContextRepository
So I figure that the whole org.springframework.security.web.server package is not on the classpath, although it should be there, since it is included in the API docs.
Seems like I am doing something wrong, but I don't know what.
Currently Spring Boot's spring-boot-starter-security does not include spring-security-webflux.
Add it as project dependency explicitly.
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-webflux</artifactId>
</dependency>
See this issue : Provide auto-configuration for WebFlux-based security.
BTW, check my working codes: https://github.com/hantsy/spring-reactive-sample/tree/master/boot
Updated: In Spring Boot 2.0.0.RELEASE, spring-boot-starter-security includes webflux support.

Resources