问题

今天升级

Spring-data-redis(1.3.0 -> 1.6.4).
Jedis(2.3.2 -> 2.7.3)

修改了Jar包的版本后,发现启动不了.启动信息一直停留在类似以下信息里:

17:00:05,421 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.weibosdk] to DEBUG
17:00:05,421 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[com.weibosdk]
17:00:05,421 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - ROOT level set to INFO
17:00:05,421 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
17:00:05,422 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@cce672c - Registering current configuration as safe fallback point

或者

Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@61ec2cb5: defining beans [xxxx]; root of factory hierarchy

Google了好久, 也困扰了好久这个问题.直到今天才想到一个笨而实用的方法…

解决

先将pom.xml切换回正常的版本. 然后查看一下它的依赖树:

mvn dependency:tree > /tmp/old.lib

然后将pom.xml切换到升级版本之后的内容,然后再查看一下它的依赖树:

mvn dependency:tree > /tmp/new.lib

然后对比一下它们的差异:

diff /tmp/old.lib /tmp/new.lib

查看一下新的依赖引入了哪些新的jar包或者版本改变了, 导致启动不了.

然后, 将除了升级指定版本的依赖以外的依赖, 通过显式指定与正常版本相同的版本即可.

例子

下面是我真实的例子, 一个是升级前的依赖,一个是升级后的依赖

╭─sky@sky-linux ~  
╰─➤  diff /tmp/old.lib /tmp/new.lib
161c161,165
< [INFO] |  |  \- org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
---
> [INFO] |  |  +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
> [INFO] |  |  +- org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
> [INFO] |  |  \- org.springframework:spring-context:jar:3.0.6.RELEASE:compile
> [INFO] |  |     +- org.springframework:spring-expression:jar:3.0.6.RELEASE:compile
> [INFO] |  |     \- org.springframework:spring-asm:jar:3.0.6.RELEASE:compile
176,177c180,181
< [INFO] +- org.springframework.data:spring-data-redis:jar:1.3.0.RELEASE:compile
< [INFO] |  +- org.springframework:spring-tx:jar:3.2.9.RELEASE:compile
---
> [INFO] +- org.springframework.data:spring-data-redis:jar:1.6.4.RELEASE:compile
> [INFO] |  +- org.springframework:spring-tx:jar:4.1.9.RELEASE:compile
178a183
> [INFO] |  +- org.springframework:spring-oxm:jar:4.1.9.RELEASE:compile
181,185c186,187
< [INFO] |  +- org.springframework:spring-context-support:jar:3.2.8.RELEASE:compile
< [INFO] |  +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
< [INFO] |  \- org.springframework:spring-context:jar:3.2.9.RELEASE:compile
< [INFO] |     \- org.springframework:spring-expression:jar:3.2.9.RELEASE:compile
< [INFO] +- redis.clients:jedis:jar:2.3.0:compile
---
> [INFO] |  \- org.springframework:spring-context-support:jar:3.2.8.RELEASE:compile
> [INFO] +- redis.clients:jedis:jar:2.7.3:compile
221c223,227
< [INFO] |  |  |  \- org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
---
> [INFO] |  |  |  +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
> [INFO] |  |  |  +- org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
> [INFO] |  |  |  \- org.springframework:spring-context:jar:3.0.6.RELEASE:compile
> [INFO] |  |  |     +- org.springframework:spring-expression:jar:3.0.6.RELEASE:compile
> [INFO] |  |  |     \- org.springframework:spring-asm:jar:3.0.6.RELEASE:compile
236,237c242,243
< [INFO] |  +- org.springframework.data:spring-data-redis:jar:1.3.0.RELEASE:compile
< [INFO] |  |  +- org.springframework:spring-tx:jar:3.2.9.RELEASE:compile
---
> [INFO] |  +- org.springframework.data:spring-data-redis:jar:1.6.4.RELEASE:compile
> [INFO] |  |  +- org.springframework:spring-tx:jar:4.1.9.RELEASE:compile
238a245
> [INFO] |  |  +- org.springframework:spring-oxm:jar:4.1.9.RELEASE:compile
241,245c248,249
< [INFO] |  |  +- org.springframework:spring-context-support:jar:3.2.8.RELEASE:compile
< [INFO] |  |  +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
< [INFO] |  |  \- org.springframework:spring-context:jar:3.2.9.RELEASE:compile
< [INFO] |  |     \- org.springframework:spring-expression:jar:3.2.9.RELEASE:compile
< [INFO] |  +- redis.clients:jedis:jar:2.3.0:compile
---
> [INFO] |  |  \- org.springframework:spring-context-support:jar:3.2.8.RELEASE:compile
> [INFO] |  +- redis.clients:jedis:jar:2.7.3:compile
269c273,277
< [INFO] |  |  |  \- org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
---
> [INFO] |  |  |  +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
> [INFO] |  |  |  +- org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
> [INFO] |  |  |  \- org.springframework:spring-context:jar:3.0.6.RELEASE:compile
> [INFO] |  |  |     +- org.springframework:spring-expression:jar:3.0.6.RELEASE:compile
> [INFO] |  |  |     \- org.springframework:spring-asm:jar:3.0.6.RELEASE:compile
282,283c290,291
< [INFO] |  +- org.springframework.data:spring-data-redis:jar:1.3.0.RELEASE:compile
< [INFO] |  |  +- org.springframework:spring-tx:jar:3.2.9.RELEASE:compile
---
> [INFO] |  +- org.springframework.data:spring-data-redis:jar:1.6.4.RELEASE:compile
> [INFO] |  |  +- org.springframework:spring-tx:jar:4.1.9.RELEASE:compile
284a293
> [INFO] |  |  +- org.springframework:spring-oxm:jar:4.1.9.RELEASE:compile
287,291c296,297
< [INFO] |  |  +- org.springframework:spring-context-support:jar:3.2.8.RELEASE:compile
< [INFO] |  |  +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
< [INFO] |  |  \- org.springframework:spring-context:jar:3.2.9.RELEASE:compile
< [INFO] |  |     \- org.springframework:spring-expression:jar:3.2.9.RELEASE:compile
< [INFO] |  +- redis.clients:jedis:jar:2.3.0:compile
---
> [INFO] |  |  \- org.springframework:spring-context-support:jar:3.2.8.RELEASE:compile
> [INFO] |  +- redis.clients:jedis:jar:2.7.3:compile
326c332
< [INFO] |  +- redis.clients:jedis:jar:2.3.0:compile
---
> [INFO] |  +- redis.clients:jedis:jar:2.7.3:compile
351,352c357,359
< [INFO] +- org.springframework.data:spring-data-redis:jar:1.3.0.RELEASE:compile
< [INFO] |  +- org.springframework:spring-tx:jar:3.2.9.RELEASE:compile
---
> [INFO] +- org.springframework.data:spring-data-redis:jar:1.6.4.RELEASE:compile
> [INFO] |  +- org.springframework:spring-tx:jar:4.1.9.RELEASE:compile
> [INFO] |  +- org.springframework:spring-oxm:jar:4.1.9.RELEASE:compile

然后, 定位看到升级后, 除了jedisspring-data-redis升级后, 还导致引入了一些额外的jar包.才导致以上的问题.

这时, 将升级后的pom.xml, 再添加上以下依赖就可以解决了:


            <!-- https://mvnrepository.com/artifact/org.springframework/spring-oxm -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-oxm</artifactId>
                <version>${spring.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>${spring.version}</version>
            </dependency>

修改后完,就可以启动了.