gigi2
gigi2

Reputation: 2194

@TestPropertySource not working?

I am trying to test my Spring Configuration. Here is my config class

@Configuration
@PropertySource("/etc/my.properties")
@ComponentScan("my.package")
public class SpringConfig {

    @Bean
    .....
}

And when I tried to test it thru my test as

@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource(locations = "classpath:test.properties")
@ContextConfiguration(classes = {SpringConfigIntTest.class, SpringConfig.class})
public class SpringConfigIntTest {
    .......
}

I keep getting the failure saying /etc/my.properties cannot be found. But I think I have overridden it with test.properties and I have been googling around without seeing other people doing it differently.

I am using spring-context, spring-beans, spring-core 4.2.2, and spring-test 4.2.4. Can someone please give me some help here? Deeply appreciate it

Upvotes: 3

Views: 6810

Answers (1)

David Siro
David Siro

Reputation: 1906

You can set the property source to not fail if the resource does not exist:

@PropertySource(value = "/etc/my.properties", ignoreResourceNotFound = true)

Upvotes: 1

Related Questions