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 8746193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:09:24+00:00 2026-06-13T12:09:24+00:00

I have a Spring MVC Controller in a very XML-slimmed application, we use a

  • 0

I have a Spring MVC Controller in a very XML-slimmed application, we use a lot of annotations and as little config as possible. The Controller is working and it also has a number of resource values injected. But I’ve experienced a really strange behavior with this controller; annotated private fields referencing other components will not be injected.
This will not work.

@Controller
public class EntranceUnitController {

    @Value("${remote.baseUrl}")
    private String baseUrl = "http://localhost";

    @Value("${remote.port}")
    private String pushPort = "8080";

    @Autowired
    private HttpClientFactory httpClientFactory;

    ...

It seems that the httpClientFactory isn’t there yet when the private fields are set, if I set a break point to inspect the value there is of course null set when the controller is created.

BUT, if I make a setter for the component and annotate the set-method instead of the private field the controller works as expected.

@Controller
public class EntranceUnitController {

    @Value("${remote.baseUrl}")
    private String baseUrl = "http://localhost";

    @Value("${remote.port}")
    private String pushPort = "8080";

    private HttpClientFactory httpClientFactory;

    @Autowired
    public void setHttpClientFactory(HttpClientFactory httpClientFactory) {
        this.httpClientFactory = httpClientFactory;
    }

    ...

To me this is really annoying. Isn’t the auto wiring injection for annotated values happening at the same time regardless injection point? I.e. why does it matter that the object is injected with a setter? I thought that private field injections are directly followed by constructs and setters, me start to think I’m wrong in that case…

  • 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-13T12:09:25+00:00Added an answer on June 13, 2026 at 12:09 pm

    Seems like your dependencies are in fact injected, you are just putting a breakpoint in the wrong moment (too early) and the dependencies aren’t injected yet, despite class being already created.

    Remember that, unless you are using constructor injection, the first place where you can use injected dependencies is @PostConstruct method:

    @Controller
    public class EntranceUnitController {
    
        @Autowired
        private HttpClientFactory httpClientFactory;
    
        @PostConstruct
        public void init() {
            httpClientFactory  //should not be null
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Spring MVC application trying to use a rich domain model, with
I have a Spring MVC web application with conroller like below : @Controller public
In my MVC 3 application I have a very basic controller [HttpPost] public ActionResult
I'm starting with Spring Web MVC. I have very simple controller and view, but
I have a controller (Spring-MVC) that generates a PDF report on a get request.
I have a doubt about Model behavior in Spring MVC. I have a controller
I have a Spring MVC application which uses FreeMarker as View technology (But maybe
I have used spring MVC with JSP/JSTL for my previous application. I was going
I have a spring mvc application that I have broken up into separate maven
I have a localized spring mvc based web application, that has an externalized messages

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.