簡體   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