Spring注入static变量

使用setter方法

1
2
3
4
5
6
7
8
9
10
11
@Service("userService")
public class UserService implements IUserService {

public static String hello;

@Value("${hello.value}")
public void setHello(String hello) {
hello = hello;
}

}

在spring容器中注入对象时赋值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Service("userService")
public class UserService implements IUserService {

public static String hello;

@Value("${hello.value}")
private String pHello;

@PostConstruct
public void init() {
hello = pHello;
}

}