SpringBoot RedisTemplate打包后找不到类

SpringBoot RedisTemplate打包后找不到类

SpringBoot 2.0.4.RELEASE 版本.

关键 POM 文件引用

        <!-- Redis -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <!-- Redis 依赖 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>

关键代码

/**
 * Redis 工具
 */
@Component
public class RedisUtil {

    @Autowired
    @Qualifier("redisTemplate")
    protected RedisTemplate redisTemplate;

}

也试过使用 @Resource 了....

在IDEA里面运行一切正常....打包后出现异常:

Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.null00.common.utils.RedisUtil] from ClassLoader [sun.misc.Launcher$AppClassLoader@55f96302]
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659)
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556)
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:541)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:244)
        ... 52 common frames omitted
**Caused by: java.lang.NoClassDefFoundError: org/springframework/data/redis/core/RedisTemplate**
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getDeclaredMethods(Unknown Source)
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641)
        ... 55 common frames omitted
**Caused by: java.lang.ClassNotFoundException: org.springframework.data.redis.core.RedisTemplate**
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 59 common frames omitted

导出后的依赖包:

lib/spring-boot-starter-jdbc-2.0.4.RELEASE.jar
lib/snakeyaml-1.19.jar
lib/spring-tx-5.0.8.RELEASE.jar
lib/tomcat-embed-el-8.5.32.jar
lib/HikariCP-2.7.9.jar
lib/spring-boot-starter-logging-2.0.4.RELEASE.jar
lib/reactor-core-3.1.8.RELEASE.jar
lib/reactive-streams-1.0.2.jar
lib/netty-codec-4.1.27.Final.jar
lib/spring-context-support-5.0.8.RELEASE.jar
lib/shiro-core-1.3.2.jar
lib/jackson-core-2.9.6.jar
lib/log4j-api-2.10.0.jar
lib/mybatis-3.4.6.jar
lib/mysql-connector-java-6.0.6.jar
lib/spring-aop-5.0.8.RELEASE.jar
lib/slf4j-api-1.7.25.jar
lib/jboss-logging-3.3.2.Final.jar
lib/spring-boot-starter-data-redis-2.0.4.RELEASE.jar
lib/mybatis-spring-boot-autoconfigure-1.3.2.jar
lib/javax.annotation-api-1.3.2.jar
lib/shiro-spring-1.3.2.jar
lib/mybatis-spring-boot-starter-1.3.2.jar
lib/log4j-to-slf4j-2.10.0.jar
lib/spring-jcl-5.0.8.RELEASE.jar
lib/spring-boot-devtools-2.0.4.RELEASE.jar
lib/spring-expression-5.0.8.RELEASE.jar
lib/netty-transport-4.1.27.Final.jar
lib/commons-pool2-2.5.0.jar
lib/spring-boot-autoconfigure-2.0.4.RELEASE.jar
lib/spring-context-5.0.8.RELEASE.jar
lib/spring-core-5.0.8.RELEASE.jar
lib/spring-boot-starter-web-2.0.4.RELEASE.jar
lib/spring-boot-configuration-processor-2.0.4.RELEASE.jar
lib/hibernate-validator-6.0.11.Final.jar
lib/commons-beanutils-1.8.3.jar
lib/spring-boot-starter-json-2.0.4.RELEASE.jar
lib/jackson-module-parameter-names-2.9.6.jar
lib/jsqlparser-0.9.4.jar
lib/spring-web-5.0.8.RELEASE.jar
lib/netty-buffer-4.1.27.Final.jar
lib/lettuce-core-5.0.4.RELEASE.jar
lib/classmate-1.3.4.jar
lib/spring-boot-starter-aop-2.0.4.RELEASE.jar
lib/spring-data-keyvalue-2.0.9.RELEASE.jar
lib/netty-common-4.1.27.Final.jar
lib/tomcat-embed-websocket-8.5.32.jar
lib/jackson-databind-2.9.6.jar
lib/spring-data-redis-2.0.9.RELEASE.jar
lib/json-simple-1.1.1.jar
lib/MiPush_SDK_Server_2_2_19.jar
lib/pagehelper-4.1.0.jar
lib/aspectjweaver-1.8.13.jar
lib/spring-webmvc-5.0.8.RELEASE.jar
lib/jackson-datatype-jsr310-2.9.6.jar
lib/spring-boot-starter-2.0.4.RELEASE.jar
lib/spring-oxm-5.0.8.RELEASE.jar
lib/xml-apis-1.4.01.jar
lib/spring-beans-5.0.8.RELEASE.jar
lib/spring-data-commons-2.0.9.RELEASE.jar
lib/jackson-annotations-2.9.0.jar
lib/netty-handler-4.1.27.Final.jar
lib/spring-boot-starter-tomcat-2.0.4.RELEASE.jar
lib/logback-classic-1.2.3.jar
lib/validation-api-2.0.1.Final.jar
lib/spring-boot-2.0.4.RELEASE.jar
lib/shiro-web-1.3.2.jar
lib/gson-2.8.2.jar
lib/logback-core-1.2.3.jar
lib/jul-to-slf4j-1.7.25.jar
lib/tomcat-embed-core-8.5.32.jar
lib/jackson-datatype-jdk8-2.9.6.jar
lib/dom4j-1.6.1.jar
lib/spring-jdbc-5.0.8.RELEASE.jar
lib/mybatis-spring-1.3.2.jar
lib/netty-resolver-4.1.27.Final.jar

------更新------

后来用查看关于依赖调用有 2 个Redis的Jar
spring-boot-starter-data-redis-2.0.4.RELEASE
spring-data-redis-2.0.9.RELEASE

通过 jd-gui 解析Jar包 spring-data-redis 才是真正实现包

在程序启动时使用 Class.forName 发现任何与该包的类都调用不了.....

3个回答

已经修好.....

通过上面的猜测...用 jd-gui 查看自己的Jar包,查看 MANIFEST.MF 文件后发现并没有引用此次更新的Jar文件,

知道MANIFEST.MF文件没有更新后,跑去看项目结构...发现一点问题都没有....百度了一下...发现了还有这样的规定

确保MANIFEST.MF的路劲在src/main/resources/META_INF/下,而不是src/main/java/META_INF/。
文献出处: https://www.cnblogs.com/showxiaxian/p/4826568.html

修改路径后重新生成项目,一调试....已经好了....卡了我一天的BUG.....

全是因为**粗心大意**......

你test包下有代码吗

XFanTian
XFanTian 回复子系天下: 谢谢,已经解决了....是MANIFEST.MF的路径问题...
9 个月之前 回复
qq_33427422
子系天下 回复XFanTian: 你没明白我的意思,打包的时候他是会执行一遍test包下的代码的,所以需要首先排查是不是因为test包下的测试代码引起的
9 个月之前 回复
XFanTian
XFanTian 我就是在IDEA里面运行没有问题,因为IDEA里面是用的Maven,但是打包出来就会崩溃....
9 个月之前 回复

没导入jedis包。。。。。。。。。。。

XFanTian
XFanTian 不.....SpringBoot的Redis导出后有Jedis包依赖的...是MANIFEST.MF文件路径的问题....
9 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问