我在Spring变量定义中做错了什么?

问题描述

在测试开始时,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配置变量。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)