混淆Spring Xml配置bean和Annotation配置bean

时间:2013-09-14 03:00:11

标签: spring spring-mvc

最近我对一件事感到困惑。 我在PlaceHolderConfigurer中定义了applicationContext.xml,在1 bean中定义了applicationContext.xml,例如它被称为myServiceproperty: name I注入值@Value($env{name}) {1}}。 此bean也注释了@Service注释,然后我在dispatch-servlet.xml中添加<Component-scan.....>。 我认为属性:name没有得到值,because Xml bean is overridden by component scan bean and PlaceHolderConfigurer不能在application context and dispatch servlet context之间共享,但实际上它具有我在属性文件中配置的值。 所以有人能为我解释一下吗? 任何事情都会受到赞赏。感谢

1 个答案:

答案 0 :(得分:0)

  1. 您创建了一个bean的两个版本 - 一个在applicationContext中定义,另一个在dispatcherServlet中定义。那通常是错的。
  2. 正如您所建议的,PlaceHolderConfigurer未在父/子上下文之间共享。它仅适用于定义的上下文。