Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active profile specified in application.properties or --spring.active.profiles is not being used. #30

Closed
adrianpillinger opened this issue Aug 21, 2013 · 2 comments

Comments

@adrianpillinger
Copy link
Contributor

I have two different implementations of a service interface X, each are annotated respectively with @service and @Profile (A and B respectively).

Another service Y has X injected.

application.properties has a property

spring.active.profiles=A

On start up neither service implementation is constructed and results in a failure to Autowire into service Y.

Not sure whether this is an error on my part or a bug in the spring boot code.

Thanks
Adrian

@philwebb
Copy link
Member

Try spring.profiles.active rather than spring.active.profiles

This test worked for me on the latest code

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class MyApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

    @Service
    @Profile("A")
    public static class MyServiceA implements CommandLineRunner {
        public void run(String... args) throws Exception {
            System.out.println("Service A");
        }
    }

    @Service
    @Profile("B")
    public static class MyServiceB implements CommandLineRunner {
        public void run(String... args) throws Exception {
            System.out.println("Service B");
        }
    }

}

@adrianpillinger
Copy link
Contributor Author

I haven't tested your suggestion, but looking back at the documentation the property was referenced by both as spring.active.profiles and spring.profiles.active so this is 99.9% sure to be the problem.

I have submitted a pull request with a documentation change. #37

Zhangshunyu pushed a commit to Zhangshunyu/spring-boot that referenced this issue Dec 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants