我试图理解变量的值来自何处,当它在Spring xml文件中被引用时。
例如:
<context:property-placeholder location="classpath:/${com.example.deploy.environment}/com.example.config/mysql.properties" ignore-resource-not-found="false" />
com.example.deploy.environment的值定义在哪里?在我的项目中,我搜遍了所有地方,但是我无法找到定义此值的任何地方。
理解这一点的任何信息都会有很大的帮助。
答案 0 :(得分:2)
此值可来自各种来源:
您可以在PropertyPlaceholderConfigurer
bean中定义的application.properties文件。
<bean id="mailProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:application.properties" />
</bean>
...
//Inside application.properties
com.example.deploy.environment=prod
您可以通过命令行提供:
使用JVM系统属性的Maven vm参数:
mvn package -Dcom.example.deploy.environment=prod
运行Spring Boot应用程序:
java -jar app.jar --com.example.deploy.environment="prod"