org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘‘

1、遇到的问题

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paymentController': Injection of autowired dependencies failed;

原因:服务单词写错了

 2、解决办法

修改正确即可,如下图:

附件:


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paymentController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'sever.port' in value "${sever.port}"
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) [spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) [spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) [spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) [spring-boot-2.6.2.jar:2.6.2]
	at com.nxg.demo.PaymentApplication.main(PaymentApplication.java:12) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_311]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_311]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_311]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_311]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.6.2.jar:2.6.2]
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'sever.port' in value "${sever.port}"
	at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180) ~[spring-core-5.3.14.jar:5.3.14]
	at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-5.3.14.jar:5.3.14]
	at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-5.3.14.jar:5.3.14]
	at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-5.3.14.jar:5.3.14]
	at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:936) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1330) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.14.jar:5.3.14]
	... 22 common frames omitted

### Spring Bean 创建异常分析 在 Spring 框架中,`BeanCreationException` 是一种常见的运行时异常,通常表示容器无法成功初始化某个 Bean。当遇到 `communityDataServiceImpl resource dependencies injection failed` 的错误提示时,这表明依赖注入过程中出现了问题。 #### 原因分析 1. **XML 配置文件中的定义不正确** 如果使用 XML 文件配置 Bean,则可能是因为 `<bean>` 定义中有误,例如未正确定义 `id` 或 `class` 属性[^1]。 2. **注解驱动的组件扫描问题** 当使用基于注解的方式(如 `@Component`, `@Service`, `@Autowired`),可能是由于缺少必要的注解或扫描路径设置不当导致目标类未能被注册到 Spring 容器中[^2]。 3. **循环依赖冲突** 若两个或多个 Bean 存在相互依赖关系而形成闭环,Spring 默认会抛出此类异常。尽管可以通过调整作用域等方式缓解部分情况下的循环依赖问题,但这并非推荐做法[^2]。 4. **资源加载失败** 对于外部资源配置(比如数据库连接池参数等),如果指定位置不存在对应文件或者读取权限受限也会引发此错误。 5. **方法拦截器处理顺序不当** 如提到的 CommonAnnotationBeanPostProcessor,在其内部实现了对于 @PostConstruct 和 @PreDestroy 注解的支持以及 JNDI lookup 功能[@Resource]. 如果存在自定义处理器影响到了这些标准行为,则可能导致预期之外的结果. #### 解决方案建议 - **检查并修正配置项** - 确认 applicationContext.xml 中关于 CommunityDataService 实现类及其所需资源(如 DAO 接口实例)的相关声明是否准确无误. - **启用调试日志级别** 设置 logging framework 至 DEBUG mode 下观察更详细的上下文信息以便定位确切原因 - **优化项目结构设计避免不必要的复杂度引入** 考虑重构代码减少间接关联程度从而降低潜在风险因素的影响范围 以下是简单的测试案例用于验证基本功能正常与否: ```java package com.example; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service("dataService") public class CommunityDataServiceImpl implements DataService { private final ResourceLoader loader; @Autowired public CommunityDataServiceImpl(ResourceLoader loader){ this.loader = loader; } } ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

所遇所思

你的鼓励将是我的原动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值