@Configuration Annotation
@Configuration
Classes annotated with the @Configuration annotation are eligible for component scanning.
and they can take advantage of @Autowired and @Inject
Classes annotated with @Configuration can be annotated with the @Profile annotation to indicate that they should be processed only
if a particular profile or profiles are active.
@Profile("development")
@Configuration
public class AppConfigDev {
@Bean
public DataSource makeData() { }
}
@Profile("production")
@Configuration
public class AppConfigProd {
@Bean
public DataSource makeData() { }
}
You can also nest the @Configuration classes as below
@Configuration
public class MyApp {
@Inject DataSource dataSource;
@Bean
public MyBean myBean() {
return new MyBean(dataSource);
}
@Configuration
static class DatabaseDS {
@Bean
DataSource dataSource() { }
}
}
Classes annotated with the @Configuration annotation are eligible for component scanning.
and they can take advantage of @Autowired and @Inject
Classes annotated with @Configuration can be annotated with the @Profile annotation to indicate that they should be processed only
if a particular profile or profiles are active.
@Profile("development")
@Configuration
public class AppConfigDev {
@Bean
public DataSource makeData() { }
}
@Profile("production")
@Configuration
public class AppConfigProd {
@Bean
public DataSource makeData() { }
}
You can also nest the @Configuration classes as below
@Configuration
public class MyApp {
@Inject DataSource dataSource;
@Bean
public MyBean myBean() {
return new MyBean(dataSource);
}
@Configuration
static class DatabaseDS {
@Bean
DataSource dataSource() { }
}
}