• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Quick basic Spring question about @ConditionalOnProperty and @ImportResource

 
Ranch Hand
Posts: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a very basic and quick question about the use of @ConditionalOnProperty and @ImportResource annotations.



If the condition is not met (that is the module.enable property is set to false in a properties file) then the ConfigA bean will not be loaded but the resources (myconf.xml) will still be imported. Am i right ?

Whether the condition is true or false, the resources will always be loaded. Correct ? Thanks for helping.
 
Bartender
Posts: 2266
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By definition, @ConditionOnProperty means when a property is specified, create the bean. Or, when a property is missing, create the bean.
It depends on the matchIfMissing is true or false.

And @ImportResource is used to import the config file in xml.
These two annotations can co-exists without conflict.

You may want to post your code on GitHub and let us run it.

Reference:
https://www.boraji.com/spring-4-import-and-importresource-example
https://stackoverflow.com/questions/26394778/what-is-purpose-of-conditionalonproperty-annotation/26403131
reply
    Bookmark Topic Watch Topic
  • New Topic