本文介绍: 经过排查后,因为springioc容器加载bean默认使用无参构造进行初始化,该实现使用了@AllArgsConstructor注解,而@Value注入一个属性值,其并不会存在于Spring容器,所以报错

 报错信息

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-06-20 17:41:32.653 ERROR 9192 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of constructor in com.linksoul.zfau.aiops.service.MsgPushServiceImpl required a bean of type 'java.lang.String' that could not be found.


Action:

Consider defining a bean of type 'java.lang.String' in your configuration.
@Service
@AllArgsConstructor
public class MsgPushServiceImpl {
    @Value("${msg.appId}")
    private String APPID;
...
}

原因:

经过排查后,因为springioc容器加载bean默认使用无参构造进行初始化,该实现层使用了@AllArgsConstructor注解,而@Value注入一个属性值,其并不会存在于Spring容器,所以报错。

解决方案

     将@RequiredArgsConstructor注解替换@AllArgsConstructor注解即可

@Service
@RequiredArgsConstructor
public class MsgPushServiceImpl {
    @Value("${msg.appId}")
    private String APPID;
...
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注