Spring Profiles: Simple example of ActiveProfilesResolver?

后端 未结 1 1333
Happy的楠姐
Happy的楠姐 2021-02-20 14:23

what am I doing?
I have an app that I want to test across different environments - dev, staging, etc

What I do?
I am using

1条回答
  •  后悔当初
    2021-02-20 14:30

    Try this. I learned from different places and created the following. It works for me

    public class SpringActiveProfileResolver implements ActiveProfilesResolver {
    
        @Override
        public String[] resolve(final Class aClass) {
            final String activeProfile = System.getProperty("spring.profiles.active");
            return new String[] { activeProfile == null ? "integration" : activeProfile };
        }
    }
    

    and on you test class do this

    @ActiveProfiles(resolver = SpringActiveProfileResolver.class)
    public class IT1DataSetup {
    ......
    }
    

    0 讨论(0)
提交回复
热议问题