@ActiveProfiles not assigned to configuration

My active profiles work fine if I install them as VM args.

I have a test that I want to use @ActiveProfiles("local").

Here is the annotation I'm using:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/jpaContext.xml")
@ActiveProfiles("local")
public class MyServiceTest {

When I try to run, I get the following in my trace:

Caused by: java.io.FileNotFoundException: class path resource [properties/database-configuration-${spring.profiles.active}.properties] cannot be opened because it does not exist

Any thoughts on why this value is not being used?

+3
source share
1 answer

When you define a placeholder value spring.profiles.activein your configuration file, Spring defaults to the system properties for the value and gets the value when you set it as a system property.

, , , . , bean :

<beans profile="local">
    <context:property-placeholder location="classpath:database-config-local.properties"/>
</beans>

<beans profile="dev">
    <context:property-placeholder location="classpath:database-config-dev.properties"/>
</beans>
+5

Source: https://habr.com/ru/post/1537472/


All Articles