可能是问题标题似乎是重复的,但我得到相同的错误,并不能找到答案在stackoverflow。无法autowire字段注入自动装配依赖失败
我有一个控制器
@Controller
public class MyController{
@Autowired
BeanA beanA;
@RequestMapping(value="/home")
public String showHomeScreen(){
return "home";
}
}
我BeanA类:
public class BeanA
{
private Map<Object, Object> maps;
//Setters,Getters
}
我在春天的配置以这种方式
<bean id="beanA" class="com.mycompany.beans.BeanA">
<property name="maps">
<map>
<entry key="Key 1" value="1" />
<entry key="Key 2" value="2" />
</map>
</property>
</bean>
更新配置BeanA:
堆栈跟踪:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mycompany.beans.BeanA com.mycompany.controller.MyController.beanA ; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.mycompany.beans.BeanA] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
我也注册了我的上下文基础包现在
<context:component-scan base-package="com.mycompany.*"/>
当我部署我的应用程序获得尽可能无法自动装配场“beanA”自动装配Autowired依赖注射失败的错误。
有人可以帮我摆脱这个问题....
你的代码不能编译,你还没有提供异常和spring配置文件的堆栈跟踪。 – 2014-10-04 05:59:39
已更新stacktrace ...看起来它试图将BeanA类映射到mycontroller beanA ...您可以在堆栈跟踪中看到它说com.mycompany.beans.BeanA com.mycompany.controller.MyController.beanA – pathfinder 2014-10-07 07:00:07
I可以看到Bean com.mycompany.beans.BeanA未注册.... from stacktrace:没有符合条件的bean [com.mycompany.beans.BeanA] – pathfinder 2014-10-07 07:14:50