lundi 9 novembre 2020

What am I doing wrongly in Spring variables definition?

At the start of a test, Spring starts to create the context. My root config test XML file starts are:

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

The spr-properties file is the real file, used at the deployment of the real application. It takes some variables from the command line parameters. Among them is the spr.root.dir variable. In the test, I have to set it elsewhere. I used the advice from https://stackoverflow.com/a/36094573/715269. In the root config test XML file, I defined the file where the properties are set, and I set

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

also, I tried

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

But still, I am getting "Failed to load 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)

The test class:

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;
    ...
}

It seems I do not understand how to set the Spring config variables.

Aucun commentaire:

Enregistrer un commentaire