I want to target static fields to @Autowired

Especially when designing utility classes, there are times when you want to target static fields to @ Autowired. In this case, it seems that you should define the setter of the target static field as a non-static method and add @Autowired to that setter. The following is an example.

public class SampleClass {

    private static StaticField staticField;

    @Autowired
    public void setStaticField(StaticField staticField) {
        SampleClass.staticField = staticField;
    }

}

However, since it is bad know-how, if you have to repeat the above frequently, it seems that you will need to review the design, such as making the class a singleton. The reality of system development is that the design cannot be reviewed so easily (´ ・ ω ・ `).

Recommended Posts

I want to target static fields to @Autowired
I want to use @Autowired in Servlet
I want to convert characters ...
Swift: I want to chain arrays
I want to use FormObject well
I want to convert InputStream to String
I want to docker-compose up Next.js!
I want to write a nice build.gradle
I want to eliminate duplicate error messages
I want to make an ios.android app
I want to display background-ground-image on heroku.
I want to use DBViewer with Eclipse 2018-12! !!
I want to RSpec even at Jest!
I want to install PHP 7.2 on Ubuntu 20.04.
I want to stop Java updates altogether
I want to do team development remotely
I want to test Action Cable with RSpec test
I want to sort by tab delimited by ruby
I want to output the day of the week
Run R from Java I want to run rJava
[Swift] I want to draw grid lines (squares)
I want to send an email in Java.
I want to use arrow notation in Ruby
[Ruby] I want to do a method jump!
I want to use java8 forEach with index
I want to var_dump the contents of the intent
I want to pass APP_HOME to logback in Gradle
I want to simply write a repeating string
I want to design a structured exception handling
rsync4j --I want to touch rsync in Java.
I want to play with Firestore from Rails
[Xcode] I want to manage images in folders
I want to be eventually even in kotlin
I want to write quickly from java to sqlite
I want to truncate after the decimal point
I want to reduce simple mistakes. To command yourself.
I want to perform aggregation processing with spring-batch
[Rails] I want to load CSS with webpacker
I want to delete files managed by Git
I want to get the value in Ruby
I want to use Combine in UIKit as well.
I want to use Clojure's convenient functions in Kotlin
I want to call a method of another class
I want to do something like "cls" in Java
[Java] I want to calculate the difference from the date
I want to use NetBeans on Mac → I can use it!
I want to embed any TraceId in the log
Pointcut Expression I want to specify more than one
I want to use fish shell in Laradock too! !!
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I learned stream (I want to convert List to Map <Integer, List>)
I want to judge the range using the monthly degree
I want to use a little icon in Rails
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to monitor a specific file with WatchService
I want to authenticate users to Rails with Devise + OmniAuth
I want to define a function in Rails Console
[Android Studio] I want to use Maven library on Android
I want to transition screens with kotlin and java!
[Swift] I want to do something like C's sprinftf