典型用法 注入常量值 @Value("Hello World") private String message; 注入配置文件中的屬性值(如 application.properties) // 假設你有如下配置: app.name=MyApp app.version=1.0.0// Java 類中使用: @Value("${app.name}") private String appName;@Value("${app.version}") private String appVersion; 設置默認值(如果屬性不存在) @Value("${user.role:guest}") private String role; 注入系統環境變量或 JVM 參數 @Value("${JAVA_HOME}") private String javaHome;@Value("${user.timezone}") private String timeZone; 注入 SpEL 表達式(Spring Expression Language) @Value("#{systemProperties['user.name']}") private String userName;@Value("#{T(java.lang.Math).random() * 100}") private double randomValue;