Java 当我尝试使用Spring和file.properties时,我看到了错误
我尝试将Spring与file.properties一起使用,但发现错误:Java 当我尝试使用Spring和file.properties时,我看到了错误,java,spring,Java,Spring,我尝试将Spring与file.properties一起使用,但发现错误: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Configuration problem: Id is required for element 'properties' when used as a top-level tag Offending resource: cl
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Configuration problem: Id is required for element 'properties' when used as a top-level tag
Offending resource: class path resource [di.xml]
Offending resource: class path resource [di.xml]
我该怎么办?
我有:
Java类
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@AllArgsConstructor(onConstructor = @__(@Autowired))
@Value
@Component("person")
@NoArgsConstructor(force = true)
public class SimplePerson implements Person {
String firstName;
String lastName;
@org.springframework.beans.factory.annotation.Value("20")
int age;
Contact contact;
}
firstName=Roma
lastName=Izmailov
age=20
Spring.xml文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
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/util
http://www.springframework.org/schema/util/spring-util.xsd">
<context:annotation-config/>
<context:component-scan base-package="cours"/>
<util:properties location="classpath:person.properties"/>
<!--<bean class="java.lang.Integer" id="age" c:value="18"/>-->
<bean class="java.lang.String" id="firstName" c:value="${firstName}" />
<bean class="java.lang.String" id="lastName" c:value="${lastName}"/>
<bean class="java.lang.String" id="type" c:value="telephone"/>
<bean class="java.lang.String" id="value" c:value="0504540"/>
尝试将id属性添加到util:properties:
<util:properties id="someId" location="classpath:person.properties"/>
尝试将id属性添加到util:properties:
<util:properties id="someId" location="classpath:person.properties"/>
谢谢,但这没有帮助我希望问题末尾提到的“file.properties”只是bean配置中提到的“person.properties”的拼写错误。你能检查一下吗?我在.xml文件中写了“person.properties”是的,我明白了。但是在属性文件中,您编写的内容被标记为“file.properties”,谢谢,但是它没有帮助我希望您问题末尾提到的“file.properties”只是bean配置中提到的“person.properties”的一个拼写错误。你能检查一下吗?我在.xml文件中写了“person.properties”是的,我明白了。但是在属性文件中,您编写的内容被标记为“file.properties”