The class is annotated with @SpringBootApplication.
And for the record, the following is the constructor that is called by Spring Boot during the creation of the bean application :
public BwsApplication(ConfigClass configClass) {
config = configClass;//SONAR - Remove this assignment of "config"
}
The SpringBootApplication represented by this class will be instantiated one and only one time. So from a logical point of view, it seems not invalid to make this field a static field. But in the facts, making it static or no doesn't matter as it will be shared with no more than one instance. You spare nothing by making it static.
I think you made the field static because you would use it in the static main method.
But it is the not the way to do that.
Instead, remove the static modifier and move this code in a instance @PostConstruct method that will be executed after the dependency injection was performed on this bean :
Connection con = config.getConnection();
int number = StudentsManager.getStudentsNumber(con);
QuartzApp qa = new QuartzApp(config);
qa.excecution(number );
In this way, you could refer the config field even it is an instance field.
It could look like :
@SpringBootApplication
public class BwsApplication {
private ConfigClass config;
public BwsApplication(ConfigClass configClass) {
config = configClass;//SONAR - Remove this assignment of "config"
}
public static void main(String[] args) throws SQLException {
SpringApplication.run(BwsApplication.class, args);
}
@PostConstruct
private void postConstruct() {
Connection con = config.getConnection();
int number = StudentsManager.getStudentsNumber(con);
QuartzApp qa = new QuartzApp(config);
qa.excecution(number);
}
}