0

テストの開始時に、Spring はコンテキストの作成を開始します。私のルート構成テスト 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:aop="http://www.springframework.org/schema/aop"
       xmlns:trx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:sec="http://www.springframework.org/schema/security" xmlns:util="http://www.springframework.org/schema/util"
       xmlns:ctx="http://www.springframework.org/schema/context" xmlns:jms="http://www.springframework.org/schema/jms"
       xmlns:beans="http://www.springframework.org/schema/beans" xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.4.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
">
        <bean id="mailProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location" value="classpath:beans_sets/test.properties" />
        </bean>


        <bean id="U01UhradaService" class="amcssz.spr.srv.main.service.U01UhradaService" />

        <import resource="classpath:META-INF/spring/spr-properties.xml" />

</beans>

spr-properties ファイルは、実際のアプリケーションのデプロイ時に使用される実際のファイルです。コマンド ライン パラメータからいくつかの変数を取得します。その中には、spr.root.dir 変数があります。テストでは、別の場所に設定する必要があります。https://stackoverflow.com/a/36094573/715269からのアドバイスを使用しました。ルート構成テスト XML ファイルで、プロパティを設定するファイルを定義し、

spr.root.dir="apv/main-app/work"

また、私は試しました

spr.root.dir=apv/main-app/work

それでも、「ApplicationContextのロードに失敗しました」というメッセージが表示されます

Caused by: org.springframework.beans.factory.BeanInitializationException: Could not load properties; 
nested exception is java.io.FileNotFoundException: ${spr.root.dir}\spr.properties (The system cannot find the path specified)

テストクラス:

package amcssz.spr.srv.main.jobs;

import amcssz.spr.srv.main.service.U01UhradaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;

@Test
@ContextConfiguration(locations={ "classpath:beans_sets/UhradyForIns.xml" })

public class OdeslatADostatJakobyAutomatickyUhradu extends AbstractTestNGSpringContextTests {
    @Autowired( required = true )
    U01UhradaService service;
    ...
}

Spring 構成変数の設定方法がわからないようです。

4

0 に答える 0