【问题标题】:unable to Autowire in Spring无法在 Spring 中自动装配
【发布时间】:2013-11-12 13:27:26
【问题描述】:

我现在已经在这里提出过这个问题,但我真的尝试过使用讨论,但没有一个对我有用。

基本上,我收到“元素“context:annotation-config”的前缀“context”未绑定”错误,我使用@Autowired 排除在bean xml 中使用属性元素。

这是我的xml文件的标签

xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.0.xsd">

我也有

<context:annotation-config/>  

自动注册 AutowiredAnnotationBeanProcessor

问题可能来自于类路径中缺少的 jar,无法在命名空间和 spring jar 之间建立映射?这是外部罐子

org.springframework.aop-3.1.0.M2

org.springframework.asm-3.1.0.M2

org.springframework.beans-3.1.0.M2

org.springframework.context.support-3.1.0.M2

org.springframework.context-3.1.0.M2

org.springframework.core-3.1.0.M2

org.springframework.expression-3.1.0.M2

spring-context-3.0.6

spring-beans-3.0.6

commons-logging-1.1.1

【问题讨论】:

  • 你为什么使用旧的里程碑版本的 spring(我会使用 3.1.4.RELEASE)并且你应该永远混合 spring 版本,你正在混合 3.0.6 和3.1.0.M2。
  • 这就是我在我的存储库中发现的!不过你可能是对的。

标签: java spring annotations autowired


【解决方案1】:

你缺少的是命名空间前缀声明:

<beans xmlns:context="http://www.springframework.org/schema/context">

【讨论】:

    猜你喜欢
    • 2017-12-18
    • 2016-09-27
    • 2013-01-29
    • 2019-01-10
    • 2018-12-27
    • 2021-04-02
    • 2017-02-05
    • 1970-01-01
    • 2023-04-08
    相关资源
    最近更新 更多