org.springframework.boot.autoconfigure.autoconfiguration.imports 未生效

问题背景

搭建SpringCloud项目的时候,用户验证中心模块引用了Redis缓存模块,需要将RedisService使用@Autowired注解注入UserService。

除开在RedisService里添加@Component注解之外,还需要在resources下添加一个加载自动装配的类的文件。

郭慕荣博客园-spring boot项目中org.springframework.boot.autoconfigure.AutoConfiguration.imports和META-INF.spring下的文件的作用汇总

照葫芦画瓢,springboot2.7之后,推荐使用org.springframework.boot.autoconfigure.autoconfiguration.imports。

在resources下添加META-INF文件夹,再在META-INF下添加spring文件夹,再添加org.springframework.boot.autoconfigure.autoconfiguration.imports文件

按需要添加之后,启动用户验证中心,控制台报错如下:

Description:

Field redisService in UserServiceImpl required a bean of type 'RedisService' 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 'RedisService' in your configuration.

问题分析

路径

该文件应在src/main/resources/META-INF/spring/下,查看是否写成了src/main/resources/META-INF.spring/。

没写错,pass。

核对文件内容

类的绝对路径是否一样。

一样,pass。

查看target

META-INF及下面的文件是否打包进去。

没有。

查看redis缓存模块的pom文件,发现多复制了一个

<packaging>pom</packaging>

wh柒八九
-maven的<packaging>pom</packaging>如何使用

问题解决

删掉redis缓存模块pom文件中的<packaging>pom</packaging>

mvn clean

重启用户验证中心。

成功。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值