user9680767
user9680767

Reputation:

When i try to use Spring and file.properties, i see error

I try to use Spring with file.properties, but i see error:

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]

What should I do? I have: Java class

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;
}

Spring .xml file

<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"/>

file.properties

firstName=Roma
lastName=Izmailov
age=20

Upvotes: 0

Views: 62

Answers (1)

zolv
zolv

Reputation: 1902

Try to add id attribute to util:properties:

<util:properties id="someId" location="classpath:person.properties"/>

Upvotes: 2

Related Questions