Record a maven conflict to solve the idea

Introduction

Quartz class loader starts abnormally after introducing jedis+Spring Data Redis

Process

1. First, according to the Spring version: 4.3.25.RELEASE, maven enters a dependency:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>1.8.23.RELEASE</version>
</dependency>
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.0</version>
</dependency>

2. Encountered the following problems:

[ERROR] org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'quartzScheduler' defined in class path resource [applicationContext-quartz.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.quartz.SchedulerContext.put(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;

3. Error analysis:
When the introduction of A causes B to make an error, it may be a dependency error. Then check the dependency of spring-data-redis and quartz:
rely
rely
I was surprised to find that quartz-all 1.6 has no dependency, but the dependency of spring-data-redis on slf4j is very suspicious. Since there is no troubleshooting idea, we can only start with slf4j: upgrade the 1.6.1 version of slf4j directly referenced by pom:

  <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.25</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.25</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jcl-over-slf4j</artifactId>
      <version>1.7.25</version>
    </dependency>

4. Run again, the error is as follows:

[ERROR] org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'quartzScheduler' defined in class path resource [applicationContext-quartz.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.quartz.SchedulerContext.put(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;

That's right, the error hasn't changed at all. So based on my maven repository, I checked quartz-all:
quartz
Although I don’t know quartz, I can’t believe the maintenance time. At the same time, I found this:
quartz
if I guessed correctly, quartz must be quartz-all. The subsequent version was changed to the latest version in angrily (it depends on slf1.7.x):

<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>2.3.2</version>
</dependency>

Then run the program, an error is reported and the label error is displayed. According to the
blog guidelines , no more errors are reported and the program starts normally.

Doubt

According to maven's shortest path principle, since slf4j already exists in this pom and is in effect, the slf4 version referenced by redis-spring is still the version of slf4j that already exists in the pom, so why does the function of quartz fail?
All in all, I feel that the solution of this problem is a crooked approach, and everyone is welcome to study the nature of the problem together.

Guess you like

Origin blog.csdn.net/weixin_44159662/article/details/108996972