M
M
Maks Burkov2017-03-13 01:26:07
Spring
Maks Burkov, 2017-03-13 01:26:07

How to correctly configure List in spring.xml?

I get acquainted with the spring, I don’t understand why it swears in my case?
user.class

public class User {

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getUsedId() {
        return usedId;
    }

    public void setUsedId(String usedId) {
        this.usedId = usedId;
    }

    public List<Address> getAddress() {
        return addresses;
    }

    public void setAddress(Address address) {
        this.addresses.add(address);
    }

    public List<Message> getMessage() {
        return messages;
    }

    public void setMessage(Message message) {
        this.messages.add(message);
    }

    @Override
    public String toString() {
        return "User{" +
                "firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", email='" + email + '\'' +
                ", usedId='" + usedId + '\'' +
                ", address=" + addresses +
                ", message=" + messages +
                '}';
    }

    private String firstName;
    private String lastName;
    private String email;
    private String usedId;

    // One to Many relationship
    private List<Address> addresses;

    // One To Many relationship
    private List<Message> messages;

}

d1537bdc1bd94237af7fc1440222fcf7.jpg816f2146e85e416ab7006055a441845f.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Khrustalev, 2017-03-13
@Maks00088

According to the JavaBeans specification, Spring takes the name you give it, capitalizes the first letter, and prefixes it with set to use the setAdresses() method, which is missing in your case - the setter is named incorrectly. Either change get-, setAddress() to get-, setAddresses() or write adress instead of adresses in XML

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question