Spring Properties可以通过以下几种方式来引入外部配置:
@Configuration @PropertySource("classpath:config.properties") public class AppConfig { @Value("${key}") private String value; // Other configurations... } <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:config.properties"/> </bean> <bean id="myBean" class="com.example.MyBean"> <property name="property" value="${key}"/> </bean> @Autowired private Environment env; public void someMethod() { String value = env.getProperty("key"); } 通过以上几种方式,可以方便地将外部配置文件的属性值注入到Spring Bean中,实现配置的灵活性和可维护性。