0

我正在开发一个项目,在该项目中我的项目配置为

项目配置.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>

我正在添加一个测试配置,我可以从中传递这些值

测试配置.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>

但这不起作用。我怎样才能

有定义的变量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

替换中的值project-config.xml

<bean id="awsCredentials" class="com.amazonaws.auth.BasicAWSCredentials">
            <constructor-arg
                    value="${com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator.dest.ProposalManager-accessKeyId}"/>
4

1 回答 1

3

你可以这样做,你的占位符应该得到解决。

<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>

另一种方法是在上面的 test.properties 文件中添加条目。

于 2012-10-23T22:07:25.173 回答