Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Spring mvc 如何在spring中使用sts设置类路径下的属性文件_Spring Mvc_Properties_Spring Data - Fatal编程技术网

Spring mvc 如何在spring中使用sts设置类路径下的属性文件

Spring mvc 如何在spring中使用sts设置类路径下的属性文件,spring-mvc,properties,spring-data,Spring Mvc,Properties,Spring Data,我正在学习spring并试图理解从属性文件中检索值 我正在尝试下面的方法来尝试一些样品 <util:properties id="spelProp" location="classpath:/META-INF/spelProperties.properties"></util:properties> 我尝试访问lastName以设置一个bean属性,如 <bean id="spelTeacher3Xml" class="com.learningweb.Servic

我正在学习spring并试图理解从属性文件中检索值

我正在尝试下面的方法来尝试一些样品

<util:properties id="spelProp" location="classpath:/META-INF/spelProperties.properties"></util:properties>
我尝试访问lastName以设置一个bean属性,如

<bean id="spelTeacher3Xml" class="com.learningweb.Service.SpelSampleTeacher">
<property name="lastName" value="#{spelProp[spelTeacher.lastName]}" />
</bean>

当我尝试使用STS跑步时 我犯了一个错误 “/META-INF/spelProperties.properties”不存在

有人能帮我理解这里出了什么问题吗。 在配置类路径或任何与Spring框架相关的设置时,我是否遗漏了任何项目

谢谢你的帮助 (还有,了解“classpath:”的任何参考资料都会有帮助。我试图搜索,但我得到了我正在寻找的正确资料。我试图了解classpath:does在春季的作用)
谢谢

您可能想尝试以下方法:

    <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
            <list>  
                <value>classpath:/META-INF/spelProperties.properties</value>  
            </list>  
        </property>  
    </bean>

类路径:/META-INF/spelProperties.properties


然后在spelTeacher3Xml中访问它,如:
value=“${spelTeacher.lastName}”

根据Spring的版本,请签出API或其他更专门的版本


有很多基本的Spring配置教程。不过,他们可能有点过时了

谢谢你的建议。我有一个关于使用${}的问题,我知道SPel实际上是#{}。两者都是一样的吗?在大多数情况下,它们对于给定的目的来说都是可以接受的,SpringEL只是能够做更多。
    <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
            <list>  
                <value>classpath:/META-INF/spelProperties.properties</value>  
            </list>  
        </property>  
    </bean>
    <context:annotation-config/>
    <context:property-placeholder location="classpath*:*.properties" />