Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在spring中尝试使用p-namespace重写beans.xml时出错_Java_Xml_Spring - Fatal编程技术网

Java 在spring中尝试使用p-namespace重写beans.xml时出错

Java 在spring中尝试使用p-namespace重写beans.xml时出错,java,xml,spring,Java,Xml,Spring,MainApp48.java 包com.tpoint import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MainApp48 { public static void main(String[] args) { ApplicationContext co

MainApp48.java 包com.tpoint

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp48 {

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            "Beans48.xml");

    Jhon obja = (Jhon) context.getBean("jhon");
    System.out.println(obja);
    System.out.println(obja.getName());
    System.out.println(obja.getJane().getName());

}
}
Jhon.java

package com.tpoint;

public class Jhon {

private String name;
private Jane jane;

public void setName(String name)
{
    this.name = name;
}

public void setJane(Jane jane)
{
    this.jane = jane;
}

public String getName()
{
    return this.name;
}

public Jane getJane()
{
    return this.jane;
}
}
最后是Beans48.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans http://www.springframework.org/schema    /beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<bean id ="jhon" class="com.tpoint.Jhon" 
p:name = "test name" 
p:jane-ref="jane" />

<bean id ="jane" class="com.tpoint.Jane" p:name="test jane name" />

</beans>
此代码与beans xml文件中的常规属性标记配合使用效果良好。但是我尝试使用p-namespace重写bean xml配置,我得到了这个错误。我搞不清楚出了什么问题

Exception in thread "main"        org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 13 in XML document from class path resource [Beans48.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 13; columnNumber: 21; The prefix "p" for attribute "p:name" associated with an element type "bean" is not bound.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
看起来您还没有将p名称空间添加到xml中

xmlns:p="http://www.springframework.org/schema/p"
此代码与beans xml文件中的常规属性标记配合使用效果良好。但是我尝试使用p-namespace重写bean xml配置,我得到了这个错误。我搞不清楚出了什么问题

Exception in thread "main"        org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 13 in XML document from class path resource [Beans48.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 13; columnNumber: 21; The prefix "p" for attribute "p:name" associated with an element type "bean" is not bound.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
看起来您还没有将p名称空间添加到xml中

xmlns:p="http://www.springframework.org/schema/p"