[英]Spring: How do I substitute constant values for constructor-args?
I am working on a project where I am given a project configuration as 我正在一个项目中,我得到了一个项目配置
project-config.xml 项目配置文件
<bean id="awsCredentials" class="com.amazonaws.auth.BasicAWSCredentials">
<constructor-arg
value="${com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-accessKeyId}"/>
<constructor-arg
value="${com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-secretAccessKey}"/>
</bean>
I am adding a test configuration from where I can pass this values 我正在从此处传递此值的位置添加测试配置
test-config.xml 测试配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator-destBucketName=bucketname
com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-accessKeyId=accesskey
com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-secretAccessKey=secretaccess key
<bean id="spa-evaluation-factory" class="com.myorg.sparrow..business.DummySpaEvaluationFactory"/>
<import resource="classpath:/com/myorg/sparrow/spa_adapter/project-config.xml"/>
</beans>
But this doesn't work. 但这是行不通的。 How can I
我怎样才能
have the variables defined in test-config.xml
具有在
test-config.xml
定义的变量
com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator-destBucketName=bucketname
com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-accessKeyId=accesskey
com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-secretAccessKey=secretaccess key
substitute for values in project-config.xml
替代
project-config.xml
值
<bean id="awsCredentials" class="com.amazonaws.auth.BasicAWSCredentials">
<constructor-arg
value="${com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-accessKeyId}"/>
You can do it this way, your place holders should get resolved. 您可以通过这种方式进行操作,您的占位符应该得到解决。
<context:property-placeholder location="classpath*:META-INF/spring/test.properties" local-override="true" properties-ref="localProperties" ignore-resource-not-found="true"/>
<util:properties id="localProperties">
<prop key="com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator-destBucketName">bucketname</prop>
<prop key="com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-accessKeyId">accesskey</prop>
<prop key="com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-secretAccessKey">secretaccess key</prop>
</util:properties>
Another way would be to have the entries in the test.properties file above. 另一种方法是将条目包含在上面的test.properties文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.