import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class TUtil {
// 能获取值
@Value("${spring.datasource.username}")
private String username;
// 加上static 不能获取值
@Value("${spring.datasource.username}")
private static String username;
// 若想给静态变量赋值,可以在set方法上写@Value
// spring.datasource.username的值会赋值到url上
private static String url;
@Value("${spring.datasource.username}")
public void setUrl(String url) {
this.url = url;
}
}
08-16
905