I don't know what I am doing wrong as I am new in Spring. I have the following method in the following class.
@Component
public class FileInfo {
@Autowired
ProjectConfiguration configuration;
public FileInfo() {
System.out.println("Whatever: " + configuration.getWhatever());
}
}
The methos is already highlighted in the IDE saying that it comes with a NullPointerException warning.
And this is the class I am autowiring. Notice that I am using the @Data lombok.
@Data
@Configuration
public class ProjectConfiguration implements Serializable {
private String whatever = "Whatever";
private static volatile ProjectConfiguration instance = null;
@Bean
public static ProjectConfiguration getInstance() {
if (instance == null) {
synchronized(ProjectConfiguration.class) {
if (instance == null) {
instance = new ProjectConfiguration();
}
}
}
return instance;
}
}
This is not working. I'm trying to make this ProjectConfiguration a class to store the project settings, which can be recovered, and can be changed. How can I make this work? Why isn't autowiring working? Is the problem maybe in the constructor?