Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8045567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:35:20+00:00 2026-06-05T05:35:20+00:00

If I have the following class: package com.example; import org.springframework.beans.factory.annotation.Required; public class Customer {

  • 0

If I have the following class:

package com.example;

import org.springframework.beans.factory.annotation.Required;

public class Customer 
{
    private Person person;

    public Person getPerson() {
        return person;
    }
    @Required
    public void setPerson(Person person) {
        this.person = person;
    }
}

Why in Spring is the @Required tag tied to the setter, and not the field, like this?

package com.example;

import org.springframework.beans.factory.annotation.Required;

public class Customer 
{
    @Required
    private Person person;

    public Person getPerson() {
        return person;
    }
    public void setPerson(Person person) {
        this.person = person;
    }
}

The dependency is that the property is set, but doesn’t need to be tied down to one specific setter that populates that property or field, unless I’m missing something.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:35:21+00:00Added an answer on June 5, 2026 at 5:35 am

    Traditionally a bean had properties defined as a getter and/or setter. The private field can be left out (sometimes name “virtual” field). In the new Java EE standard beans are more loose, and might also have a property defined as public field.

    Nevertheless Spring pre-dates the latest standard, and having the annotation on a method i.o. a field has the advantage that access can be intercepted via AOP (simple byte code manipulation).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple Java code: package testj; import java.util.*; public class Query<T>
I have the following Model class: package com.swaranga.model; public final class Book { private
package com.example.helloandroid; import java.io.File; import android.os.AsyncTask; import android.os.Environment; import android.widget.Toast; public class CheckTask extends
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
I have a job with name Myjob.java under package com.example.jobs . This class is
In Scala IDE I have the following code: package pkg.one object S { class
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have following class (as seen through reflector) public class W : IDisposable {
I have the following servlet coded in /src/main/java/examples/web/SimpleServlet.java : package examples.web; import java.io.IOException; import
package com.scheduler.process; public class Process { public enum state { NOT_SUBMITTED, SUBMITTED, BLOCKED, READY,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.