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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:36:54+00:00 2026-06-07T06:36:54+00:00

I know this may looks like a previously asked question but I’m facing a

  • 0

I know this may looks like a previously asked question but I’m facing a different problem here.

I have a utility class that has only static methods. I don’t and I won’t take an instance from it.

public class Utils{
    private static Properties dataBaseAttr;
    public static void methodA(){

    }

    public static void methodB(){

    }
}

Now I need Spring to fill dataBaseAttr with database attributes Properties.Spring config is:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<util:properties id="dataBaseAttr"
        location="file:#{classPathVariable.path}/dataBaseAttr.properties" />
</beans>

I already done it in other beans but the problem here in this class (Utils) isn’t a bean, And if I make it a bean nothing changes I still can’t use the variable since the class will not be instantiated and variable always equals null.

  • 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-07T06:36:56+00:00Added an answer on June 7, 2026 at 6:36 am

    You have two possibilities:

    1. non-static setter for static property/field;
    2. using org.springframework.beans.factory.config.MethodInvokingFactoryBean to invoke a static setter.

    In the first option you have a bean with a regular setter but instead setting an instance property you set the static property/field.

    public void setTheProperty(Object value) {
        foo.bar.Class.STATIC_VALUE = value;
    }
    

    but in order to do this you need to have an instance of a bean that will expose this setter (its more like an workaround).

    In the second case it would be done as follows:

    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="staticMethod" value="foo.bar.Class.setTheProperty"/>
        <property name="arguments">
            <list>
                <ref bean="theProperty"/>
            </list>
       </property>
    </bean>
    

    On you case you will add a new setter on the Utils class:

    public static setDataBaseAttr(Properties p)
    

    and in your context you will configure it with the approach exemplified above, more or less like:

    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="staticMethod" value="foo.bar.Utils.setDataBaseAttr"/>
        <property name="arguments">
            <list>
                <ref bean="dataBaseAttr"/>
            </list>
       </property>
    </bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question was asked for many times, and it may look like
I know this may seem like a math question but i just saw this
I know this may be a dumb question, but my background is more in
I know this question may well be the silliest question you've heard today, but
I know this question may be a duplicate of some other ones, but I
I know that this may be an amateur question but for some reason I
I know this questions has been asked a few times here. But these seem
This may sound like a noobish question (in fact, it is), but I can't
I feel like this may be a trivial problem for most people but I'm
This may be a no-brainer for the WPF cognoscenti, but I'd like to know

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.