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

  • SEARCH
  • Home
  • 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 3239766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:00:30+00:00 2026-05-17T18:00:30+00:00

I am working with several Spring MVC web applications and I use the getter/setter

  • 0

I am working with several Spring MVC web applications and I use the getter/setter dependency injection and configure all my beans in my app-servlet.xml file.

I believe that I am following convention with most of the properties and beans that I am injecting into my controller beans such as my DAO’s and other beans that I have specified in either my applicationContext.xml or in the app-servlet.xml

As my applications have been getting more complex and larger, the beans in these files have been filling up with more properties that are being injected.

My question is, where is the line, or what is the convention on what should be injected, and what should be specified as an instance field/variable in the controller.

Sometimes I am faced with a situation if I am going to specify the value for a field in the actual controller, or if I am going to inject the value into that controllers bean.

For example, I am using velocity template library for sending my emails. There is a path to the directory of my Velocity Templates. I am faced with doing one of the following.

In my Controller I could specify the value

 private String basePath = "/path/to/velocity/templates";

Or in my Controller bean I could inject the same value into that controller

<property name="basePath" value="/path/to/velocity/templates"/>

and in my class I would have the getters/setters for this injected value.

I am not sure where to draw the line for each.

  • 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-05-17T18:00:30+00:00Added an answer on May 17, 2026 at 6:00 pm

    I normally inject based on:

    1. whether I need to change this value per environment/deployment (e.g. using a PropertyPlaceholderConfiguration).
    2. whether I need to mock something out for testing.
    3. whether someone else is likely to consume this class in the future and want to do one of the above.

    If you’re not careful, then your configurations can become a mass of injected properties (I prefer to use constructor arguments so I can guarantee correct instantiation, but that’s another story). The above guidelines work well in limiting the number of injections whilst permitting flexibility.

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

Sidebar

Related Questions

I am working on a Spring MVC application in which I have recently been
I'm currently working with Spring 3 MVC, and in my JSP templates I'm noticing
I am trying to configure hibernate search for my application by reading several web
I've been working on this issue for a couple days and have read several
I have been working for a while on a project with the following components:
Please can someone help me. Basically I am using vb.net. All I am doing
I'm looking for some guidance as to how to set up a database I
I want to provide a templated function that converts most basic types to string.
I have a large SQL script that creates my database (multiple tables, triggers, and

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.