XML:
sgtPeppers的bean配置在JavaConfig中:
package com.soundsystem; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class CDConfig { @Bean public CompactDisc sgtPeppers(){ return new SgtPeppers(); } }
执行后报错:
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cdPlayer' defined in class path resource [META-INF/spring/cdplayer-config.xml]: Cannot resolve reference to bean 'sgtPeppers' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sgtPeppers' available
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cdPlayer' defined in class path resource [META-INF/spring/cdplayer-config.xml]: Cannot resolve reference to bean 'sgtPeppers' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sgtPeppers' available
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sgtPeppers' available
IDEA显示是绿色的,但是为什么找不到
欢迎选择我的课程,让我们一起见证您的进步~~