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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:06:42+00:00 2026-06-15T23:06:42+00:00

I have a package Utils where i have many classes. Some of them are

  • 0

I have a package “Utils” where i have many classes. Some of them are just some classes with static methods and others some singleton where i pass some parameters in constructor (with @Value in order to replace the basic XML configuration by annotation).

I have a configuration in ApplicationContext in order to scan the package.

So, my question : for classes with static methods, should we transform them with @Component annotation in order to have a singleton (still with static methods) or should we let them in this state without managed them by Spring ?

thank you

  • 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-15T23:06:42+00:00Added an answer on June 15, 2026 at 11:06 pm

    If it has any kind of state to maintain, or any collaborators then make a Spring component. If the functionality you need is stateless and doesn’t rely on the state of any other methods it calls then make it static.

    For example in my app I have a static util method that clamps integers between a min and max value, but a Spring bean that returns the current date…

    @Service
    public class DateServiceImpl implements DateService {
        @Override
        public Date getCurrentDate() {
            return Calendar.getInstance().getTime();
        }
    }
    

    Why? Because now I can unit test code that uses the current date.

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

Sidebar

Related Questions

I have a package with logic classes(like CheckAuthenticationDataLogic.java, GetVocabulariesLogic.java). And another class - ApiService.java
I have package : com.google.*.*.* There may be many subpackages. I have a Class
I have defined a many-to-many relationship between my two entity classes User and Permission.
We have many XHTML pages, each page has some <h:inputText> , <h:inputSecret> , etc..
I have tried many other questions on this site today but none of them
I have a Util package with source files in three seperate directories, defined like
I have following Code package cyclist.project; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException;
Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
I have the following simple Java code: package testj; import java.util.*; public class Query<T>
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;

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.