涛声依旧1988 2015-12-06 07:59 采纳率: 0%
浏览 4182

关于spring xml配置中的c命名空间和p命名空间的问题

图片说明

<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

c:age="29" c:axe-ref="stoneAxe"/>


package com.app.service;

public interface Person {
public void useAxe();

}
package com.app.service;

public interface Axe {
public String chop();

}
package com.app.service.impl;

import com.app.service.Axe;

public class StoneAxe implements Axe {

public String chop() {
    return "石斧头砍柴好慢";
}

}
package com.app.service.impl;

import com.app.service.Axe;

public class SteelAxe implements Axe{

public String chop() {
    return "钢斧头真快";
}

}
package com.app.service.impl;

import com.app.service.Axe;
import com.app.service.Person;

public class Chinese implements Person {
private Axe axe;
private int age;

public  Chinese(Axe axe,int age){
    this.axe = axe;
    this.age = age;
}

public void useAxe() {
    System.out.println(axe.chop());
    System.out.println("age成员变量的值:" + age);

}

}
package com.app.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.app.service.Person;

public class SpringTest {
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext("beans.xml");
Person p = ctx.getBean("chinese",Person.class);
p.useAxe();
}

}
运行测试类报错如下:
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'chinese' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:979)
at com.app.test.SpringTest.main(SpringTest.java:11)

  • 写回答

3条回答 默认 最新

  • Robot-C 2015-12-06 08:01
    关注

    <beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.springframework.org/2001/XMLSchema-instance"

    xmlns:p="http://www.springframework.org/schema/p"
    
    x......<br/><strong>答案就在这里:</strong><a target='_blank' rel='nofollow' href='http://blog.csdn.net/wangxiangmingtian/article/details/9230663'>Spring 命名空间 p</a><br/>----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题