繁体   English   中英

context:xml中的property-placeholder

[英]context:property-placeholder in xml

我是Spring框架的新手。 当我尝试在XML文件中加载属性文件时,它显示以下错误。

log4j:WARN找不到记录器的附加程序(org.springframework.context.support.ClassPathXmlApplicationContext)。 log4j:WARN请正确初始化log4j系统。 线程“主”中的异常线程“主”中的异常org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:类路径资源[byConstructor.xml]中XML文档中的第10行无效; 嵌套的异常是org.xml.sax.SAXParseException; lineNumber:10; columnNumber:70; 元素“ context:property-placeholder”的前缀“ context”未绑定。

这是我的.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<context:property-placeholder location="classpath:from.properties"/>
<bean id="u" class="dependenceInjection.ByConstructor">
    <constructor-arg value="101" type="int"></constructor-arg>
    <constructor-arg value="java"></constructor-arg>
</bean>
<bean id="impleCoach" class="dependenceInjection.ImpleCaoch">
    <property name="name" value="${value}" />
</bean>

from.properties

value=value from properties

提前致谢

正确的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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:property-placeholder location="classpath:from.properties"/>

    <bean id="u" class="dependenceInjection.ByConstructor">
        <constructor-arg value="101" type="int"></constructor-arg>
        <constructor-arg value="java"></constructor-arg>
    </bean>
    <bean id="impleCoach" class="dependenceInjection.ImpleCaoch">
        <property name="name" value="${value}" />
    </bean>
</beans>

注意:此xml将起作用。 但是我建议您在编写的xml中检查bean。

请遵循以下约定来创建bean:

示例:类: Team ,包: com.demo ,id = 该类的首字母小 ,即团队

<bean id ="team" class="com.demo.Team">
</bean>

byConstructor.xml我认为我的xml代码是正确的,您可以在下一张图片中检出,但是eclipse将<context:property-placeholder location="classpath:from.properties"/> as an error

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM