I’m working on an application which uses Jasper for report generation. I have the following accessor (I did not code it):
@Component
@RequiredArgsConstructor
public class JasperAccessor implements Serializable {
private static MyService myService;
private final MyService tMyService;
@PostConstruct
public void init() {
myService = tMyService;
}
public static A getA() {
return myService.getA();
}
}
Sonar complains in this class with rule java:S2696 (since instance methods should not write to static properties). Thus, I’m trying to fix that issue. For that, I’ve refactored the class into the following:
@Component
@RequiredArgsConstructor
public class JasperAccessor implements Serializable {
private final transient MyService myService;
public A getA() {
return myService.getA();
}
}
Before the refactor, Jasper reports would use this accessor with JasperAccessor.getA()
. This does not work anymore, but I have no idea how to use the new accessor: I need to somehow inject MyService
into it… How could I do it?