https://madplay.github.io/post/spring-framework-static-field-injection
static 변수에 autowired 설정하려면 어떻게 해야 할까?
스프링 프레임워크에서 정적 필드(static field)에 빈을 주입(injection) 해보자.
madplay.github.io
What is the right way to use an injected bean in a static method?
This question might seem a little odd. Suppose I have a Service which I want to use in a Utility class that has some static methods. The Service is a Spring bean, so naturally I will for example us...
stackoverflow.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
@Component
public class JustAClass{
private static Service service;
@Autowired
private Service tmpService;
@PostConstruct
public void init() {
service = tmpService;
}
public static void say() {
service.sayHi();
}
}
|
cs |
https://stackoverflow.com/questions/17659875/autowired-and-static-method
'[공부용]참고 사이트 모음 > [SPRING]' 카테고리의 다른 글
Spring Scheduler(스프링 스케쥴러) 설정방법 및 사용방법 (0) | 2021.07.16 |
---|---|
[SPRING] Task Scheduler 설정 및 사용방법 (0) | 2021.07.16 |
[egov] 배치 중복실행 가능여부 (0) | 2021.06.25 |
redirect시 parameter 전달 (0) | 2021.03.08 |
실시간 세션체크용 ajax - session ajax - 세션체크 / JQuery-Ajax (0) | 2020.11.06 |