Autowire a bean from spring config - Environment specific
up vote
0
down vote
favorite
I'm trying to have environment specific boolean flag. In my spring config, I defined three beans which are environment specific as per below.
<bean id="validationFlag-E1" class="java.lang.Boolean.FALSE"/>
<bean id="validationFlag-E2" class="java.lang.Boolean.TRUE"/>
<bean id="validationFlag-E3" class="java.lang.Boolean.TRUE"/>
I have also "spring.profiles.active" system property defined at server level and its value is "E1 /E2 /E3" based on the environment.
In my service, i'm trying to do autowiring as per below but it is not working and getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. Please advise me.
@Autowired
@Qualifier("validationFlag-${spring.profiles.active}")
Boolean emailInUseValidationFlag;
We can achieve the above requirement by having individual environment specific property file. But I don't want to create three property files for a single flag. So, trying above approach and I'm using spring mvc.
java spring spring-mvc
add a comment |
up vote
0
down vote
favorite
I'm trying to have environment specific boolean flag. In my spring config, I defined three beans which are environment specific as per below.
<bean id="validationFlag-E1" class="java.lang.Boolean.FALSE"/>
<bean id="validationFlag-E2" class="java.lang.Boolean.TRUE"/>
<bean id="validationFlag-E3" class="java.lang.Boolean.TRUE"/>
I have also "spring.profiles.active" system property defined at server level and its value is "E1 /E2 /E3" based on the environment.
In my service, i'm trying to do autowiring as per below but it is not working and getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. Please advise me.
@Autowired
@Qualifier("validationFlag-${spring.profiles.active}")
Boolean emailInUseValidationFlag;
We can achieve the above requirement by having individual environment specific property file. But I don't want to create three property files for a single flag. So, trying above approach and I'm using spring mvc.
java spring spring-mvc
Are you using Boot?
– chrylis
Nov 10 at 0:44
No. Using spring mvc
– user3858442
Nov 10 at 1:15
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to have environment specific boolean flag. In my spring config, I defined three beans which are environment specific as per below.
<bean id="validationFlag-E1" class="java.lang.Boolean.FALSE"/>
<bean id="validationFlag-E2" class="java.lang.Boolean.TRUE"/>
<bean id="validationFlag-E3" class="java.lang.Boolean.TRUE"/>
I have also "spring.profiles.active" system property defined at server level and its value is "E1 /E2 /E3" based on the environment.
In my service, i'm trying to do autowiring as per below but it is not working and getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. Please advise me.
@Autowired
@Qualifier("validationFlag-${spring.profiles.active}")
Boolean emailInUseValidationFlag;
We can achieve the above requirement by having individual environment specific property file. But I don't want to create three property files for a single flag. So, trying above approach and I'm using spring mvc.
java spring spring-mvc
I'm trying to have environment specific boolean flag. In my spring config, I defined three beans which are environment specific as per below.
<bean id="validationFlag-E1" class="java.lang.Boolean.FALSE"/>
<bean id="validationFlag-E2" class="java.lang.Boolean.TRUE"/>
<bean id="validationFlag-E3" class="java.lang.Boolean.TRUE"/>
I have also "spring.profiles.active" system property defined at server level and its value is "E1 /E2 /E3" based on the environment.
In my service, i'm trying to do autowiring as per below but it is not working and getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. Please advise me.
@Autowired
@Qualifier("validationFlag-${spring.profiles.active}")
Boolean emailInUseValidationFlag;
We can achieve the above requirement by having individual environment specific property file. But I don't want to create three property files for a single flag. So, trying above approach and I'm using spring mvc.
java spring spring-mvc
java spring spring-mvc
edited Nov 10 at 1:20
asked Nov 10 at 0:37
user3858442
106
106
Are you using Boot?
– chrylis
Nov 10 at 0:44
No. Using spring mvc
– user3858442
Nov 10 at 1:15
add a comment |
Are you using Boot?
– chrylis
Nov 10 at 0:44
No. Using spring mvc
– user3858442
Nov 10 at 1:15
Are you using Boot?
– chrylis
Nov 10 at 0:44
Are you using Boot?
– chrylis
Nov 10 at 0:44
No. Using spring mvc
– user3858442
Nov 10 at 1:15
No. Using spring mvc
– user3858442
Nov 10 at 1:15
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
Change your bean definition to:
<bean id="validationFlag-E1" class="java.lang.Boolean">
<constructor-arg value="false"/>
</bean>
<bean id="validationFlag-E2" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
<bean id="validationFlag-E3" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
Looks like bean definition is correct. I don't see any XML model errors. But getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. How can we resolve this?
– user3858442
Nov 10 at 15:28
In your @Qualifier not getting value for the placeholder -${spring.profiles.active} because of that you are getting this error if you want profile specific bean means you have to define like this <beans profile="E1"> <bean id="validationFlag" class="java.lang.Boolean.False"/> </beans> <beans profile="E2"> <bean id="validationFlag" class="java.lang.Boolean.True"/> </beans>
– Ajish Thankachan
Nov 10 at 16:07
Thanks a lot. It is working now.
– user3858442
Nov 10 at 20:17
add a comment |
up vote
1
down vote
You can use environmental property ${blah.blah.flag}
(or whatever name you choose) with value of a flag (false
or true
) -Dblah.blah.flag=true
and then inject that value as a property
@Value("${blah.blah.flag}")
private Boolean flag;
We can do that way but it would end up creating environment specific property file in total 3 files. I'm not interested in creating multiple files only for this single flag. So, trying the above approach.
– user3858442
Nov 10 at 1:18
1
What do you mean by specific property file? Instead of spring.profiles active you pass that flag
– Ivan
Nov 10 at 1:44
flag-E1.properties flag-E2.properties , flag-E3.properties
– user3858442
Nov 10 at 3:41
As I've said you do not need a properties file to pass properties ro Spring. You can use system and environmental properties for that
– Ivan
Nov 10 at 3:46
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Change your bean definition to:
<bean id="validationFlag-E1" class="java.lang.Boolean">
<constructor-arg value="false"/>
</bean>
<bean id="validationFlag-E2" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
<bean id="validationFlag-E3" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
Looks like bean definition is correct. I don't see any XML model errors. But getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. How can we resolve this?
– user3858442
Nov 10 at 15:28
In your @Qualifier not getting value for the placeholder -${spring.profiles.active} because of that you are getting this error if you want profile specific bean means you have to define like this <beans profile="E1"> <bean id="validationFlag" class="java.lang.Boolean.False"/> </beans> <beans profile="E2"> <bean id="validationFlag" class="java.lang.Boolean.True"/> </beans>
– Ajish Thankachan
Nov 10 at 16:07
Thanks a lot. It is working now.
– user3858442
Nov 10 at 20:17
add a comment |
up vote
0
down vote
accepted
Change your bean definition to:
<bean id="validationFlag-E1" class="java.lang.Boolean">
<constructor-arg value="false"/>
</bean>
<bean id="validationFlag-E2" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
<bean id="validationFlag-E3" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
Looks like bean definition is correct. I don't see any XML model errors. But getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. How can we resolve this?
– user3858442
Nov 10 at 15:28
In your @Qualifier not getting value for the placeholder -${spring.profiles.active} because of that you are getting this error if you want profile specific bean means you have to define like this <beans profile="E1"> <bean id="validationFlag" class="java.lang.Boolean.False"/> </beans> <beans profile="E2"> <bean id="validationFlag" class="java.lang.Boolean.True"/> </beans>
– Ajish Thankachan
Nov 10 at 16:07
Thanks a lot. It is working now.
– user3858442
Nov 10 at 20:17
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Change your bean definition to:
<bean id="validationFlag-E1" class="java.lang.Boolean">
<constructor-arg value="false"/>
</bean>
<bean id="validationFlag-E2" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
<bean id="validationFlag-E3" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
Change your bean definition to:
<bean id="validationFlag-E1" class="java.lang.Boolean">
<constructor-arg value="false"/>
</bean>
<bean id="validationFlag-E2" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
<bean id="validationFlag-E3" class="java.lang.Boolean">
<constructor-arg value="true"/>
</bean>
answered Nov 10 at 6:57
Ajish Thankachan
612
612
Looks like bean definition is correct. I don't see any XML model errors. But getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. How can we resolve this?
– user3858442
Nov 10 at 15:28
In your @Qualifier not getting value for the placeholder -${spring.profiles.active} because of that you are getting this error if you want profile specific bean means you have to define like this <beans profile="E1"> <bean id="validationFlag" class="java.lang.Boolean.False"/> </beans> <beans profile="E2"> <bean id="validationFlag" class="java.lang.Boolean.True"/> </beans>
– Ajish Thankachan
Nov 10 at 16:07
Thanks a lot. It is working now.
– user3858442
Nov 10 at 20:17
add a comment |
Looks like bean definition is correct. I don't see any XML model errors. But getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. How can we resolve this?
– user3858442
Nov 10 at 15:28
In your @Qualifier not getting value for the placeholder -${spring.profiles.active} because of that you are getting this error if you want profile specific bean means you have to define like this <beans profile="E1"> <bean id="validationFlag" class="java.lang.Boolean.False"/> </beans> <beans profile="E2"> <bean id="validationFlag" class="java.lang.Boolean.True"/> </beans>
– Ajish Thankachan
Nov 10 at 16:07
Thanks a lot. It is working now.
– user3858442
Nov 10 at 20:17
Looks like bean definition is correct. I don't see any XML model errors. But getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. How can we resolve this?
– user3858442
Nov 10 at 15:28
Looks like bean definition is correct. I don't see any XML model errors. But getting No qualifying bean of type 'java.lang.Boolean' available: expected at least 1 bean which qualifies as autowire candidate. How can we resolve this?
– user3858442
Nov 10 at 15:28
In your @Qualifier not getting value for the placeholder -${spring.profiles.active} because of that you are getting this error if you want profile specific bean means you have to define like this <beans profile="E1"> <bean id="validationFlag" class="java.lang.Boolean.False"/> </beans> <beans profile="E2"> <bean id="validationFlag" class="java.lang.Boolean.True"/> </beans>
– Ajish Thankachan
Nov 10 at 16:07
In your @Qualifier not getting value for the placeholder -${spring.profiles.active} because of that you are getting this error if you want profile specific bean means you have to define like this <beans profile="E1"> <bean id="validationFlag" class="java.lang.Boolean.False"/> </beans> <beans profile="E2"> <bean id="validationFlag" class="java.lang.Boolean.True"/> </beans>
– Ajish Thankachan
Nov 10 at 16:07
Thanks a lot. It is working now.
– user3858442
Nov 10 at 20:17
Thanks a lot. It is working now.
– user3858442
Nov 10 at 20:17
add a comment |
up vote
1
down vote
You can use environmental property ${blah.blah.flag}
(or whatever name you choose) with value of a flag (false
or true
) -Dblah.blah.flag=true
and then inject that value as a property
@Value("${blah.blah.flag}")
private Boolean flag;
We can do that way but it would end up creating environment specific property file in total 3 files. I'm not interested in creating multiple files only for this single flag. So, trying the above approach.
– user3858442
Nov 10 at 1:18
1
What do you mean by specific property file? Instead of spring.profiles active you pass that flag
– Ivan
Nov 10 at 1:44
flag-E1.properties flag-E2.properties , flag-E3.properties
– user3858442
Nov 10 at 3:41
As I've said you do not need a properties file to pass properties ro Spring. You can use system and environmental properties for that
– Ivan
Nov 10 at 3:46
add a comment |
up vote
1
down vote
You can use environmental property ${blah.blah.flag}
(or whatever name you choose) with value of a flag (false
or true
) -Dblah.blah.flag=true
and then inject that value as a property
@Value("${blah.blah.flag}")
private Boolean flag;
We can do that way but it would end up creating environment specific property file in total 3 files. I'm not interested in creating multiple files only for this single flag. So, trying the above approach.
– user3858442
Nov 10 at 1:18
1
What do you mean by specific property file? Instead of spring.profiles active you pass that flag
– Ivan
Nov 10 at 1:44
flag-E1.properties flag-E2.properties , flag-E3.properties
– user3858442
Nov 10 at 3:41
As I've said you do not need a properties file to pass properties ro Spring. You can use system and environmental properties for that
– Ivan
Nov 10 at 3:46
add a comment |
up vote
1
down vote
up vote
1
down vote
You can use environmental property ${blah.blah.flag}
(or whatever name you choose) with value of a flag (false
or true
) -Dblah.blah.flag=true
and then inject that value as a property
@Value("${blah.blah.flag}")
private Boolean flag;
You can use environmental property ${blah.blah.flag}
(or whatever name you choose) with value of a flag (false
or true
) -Dblah.blah.flag=true
and then inject that value as a property
@Value("${blah.blah.flag}")
private Boolean flag;
edited Nov 10 at 1:17
answered Nov 10 at 0:57
Ivan
4,4891720
4,4891720
We can do that way but it would end up creating environment specific property file in total 3 files. I'm not interested in creating multiple files only for this single flag. So, trying the above approach.
– user3858442
Nov 10 at 1:18
1
What do you mean by specific property file? Instead of spring.profiles active you pass that flag
– Ivan
Nov 10 at 1:44
flag-E1.properties flag-E2.properties , flag-E3.properties
– user3858442
Nov 10 at 3:41
As I've said you do not need a properties file to pass properties ro Spring. You can use system and environmental properties for that
– Ivan
Nov 10 at 3:46
add a comment |
We can do that way but it would end up creating environment specific property file in total 3 files. I'm not interested in creating multiple files only for this single flag. So, trying the above approach.
– user3858442
Nov 10 at 1:18
1
What do you mean by specific property file? Instead of spring.profiles active you pass that flag
– Ivan
Nov 10 at 1:44
flag-E1.properties flag-E2.properties , flag-E3.properties
– user3858442
Nov 10 at 3:41
As I've said you do not need a properties file to pass properties ro Spring. You can use system and environmental properties for that
– Ivan
Nov 10 at 3:46
We can do that way but it would end up creating environment specific property file in total 3 files. I'm not interested in creating multiple files only for this single flag. So, trying the above approach.
– user3858442
Nov 10 at 1:18
We can do that way but it would end up creating environment specific property file in total 3 files. I'm not interested in creating multiple files only for this single flag. So, trying the above approach.
– user3858442
Nov 10 at 1:18
1
1
What do you mean by specific property file? Instead of spring.profiles active you pass that flag
– Ivan
Nov 10 at 1:44
What do you mean by specific property file? Instead of spring.profiles active you pass that flag
– Ivan
Nov 10 at 1:44
flag-E1.properties flag-E2.properties , flag-E3.properties
– user3858442
Nov 10 at 3:41
flag-E1.properties flag-E2.properties , flag-E3.properties
– user3858442
Nov 10 at 3:41
As I've said you do not need a properties file to pass properties ro Spring. You can use system and environmental properties for that
– Ivan
Nov 10 at 3:46
As I've said you do not need a properties file to pass properties ro Spring. You can use system and environmental properties for that
– Ivan
Nov 10 at 3:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234986%2fautowire-a-bean-from-spring-config-environment-specific%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you using Boot?
– chrylis
Nov 10 at 0:44
No. Using spring mvc
– user3858442
Nov 10 at 1:15