0

I have beans:

@Configuration
@PropertySource("classpath:bean.properties")
class Config{

  @Bean
  @ConditionalOnProperty(name = "property.validation")
  @Order(1)
  public BeanInterface beanInterface(@Value("${property.validation}" String valid) {
     return new MyBean(valid);
  }

  @Bean("beanInterface")
  @ConditionalOnMissingBean(MyBean.class)
  @Order(2)
  public BeanInterface beanInterface() {
     return new MyBean2();
  }
}

Now, if "property.validation" exists inside "bean.properties" file, MyBean() is created, if the property does not exists MyBean2() is created, however, if bean.properties file does not exists neither is created. And i want to create MyBean2 if the file does not exists.

Can i achieve something like this with spring?

Johnyb
  • 980
  • 1
  • 12
  • 27
  • Please don't ask [the same question](https://stackoverflow.com/questions/71050738/create-specific-bean-dependant-on-property) again. There is already an answer to that question. – M. Deinum Feb 10 '22 at 09:51
  • Try moving the second bean to a different `@Configuration` class. That way it no longer depends on this `Config` class, which depends on the `bean.properties` file. It will only depend on the absence of the `MyBean.class` bean. – Rob Spoor Feb 10 '22 at 09:51

0 Answers0