Skip to content
Advertisement

Failed to parse configuration class, nested exception is java.io.FileNotFoundException: Could not open resource [/test.properties]

I´m trying to configurate new properties for the test, so I created a test config class:

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.scheduling.annotation.EnableAsync;
@Configuration
@EnableAsync
@ComponentScan("ar.com.yo")
@PropertySource("test.properties")

public class TestConfig {

}

Properties file is in src/test/resources/test.properties

and in the test class :

@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = TestConfig.class)
public class InsumoServiceTest {
...
}

when I execute the tests the error is: Failed to parse configuration class [ar.com.yo.myproject.main.TestConfig]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/test.properties]

Advertisement

Answer

It seems that the requested properties can’t be found. I would recommend doing this: is that resolve your problem :

@PropertySource("classpath:test.properties")
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement