First thanks for taking the time help. You are all Awesome!
My question: Say i have some nested properties in my application.yml
regions:
region1:
delayTime: 10
threads: 2
region2:
delayTime: 5
threads: 1
and a respective component with a config for the regions
@Component
public class Region{
public int delayTime;
public int threads;
}
@Configuration
public class RegionConfig{
@Bean("region1props")
@ConfigurationProperties(prefix ="regions.region1")
public Region getRegion1(){
returns new Region();
}
@Bean("region2props")
@ConfigurationProperties(prefix ="regions.region2")
public Region getRegion2(){
returns new Region();
}
}
If say I also had a RegionHandler Component that had Region as a dependency:
@Component
public class RegionHandler{
@AutoWired
Region region;
}
ULTIMATELY i want a RegionOnePublisher and RegionTwoPublisher Component with no config:
@Component
public class RegionOnePublisher{
@Autowired
RegionHandler regionOne;// <-- need to configure Region depenandcy as "region1props" bean
}
//----------------------------------------------
@Component
public class RegionTwoPublisher{
@Autowired
RegionHandler regionTwo; // <-- need to configure Region depenandcy as "region2props" bean
}
How would I go about defining the config class for RegionHandler object such that @Bean("region1props") is the Region bean dependancy injected for a RegionHandler regionOne and @Bean("region2props") as the Region bean dependancy for RegionHandler regionTwo?
What I have: [Edited]
@Component
public class RegionOnePublisher{
@Autowired
@Qualifier("regionOneProps")
RegionHandler regionOne;// <-- need to configure Region depenandcy as "region1props" bean
}
//----------------------------------------------
@Component
public class RegionTwoPublisher{
@Autowired
@Qualifier("regionTwoProps")
RegionHandler regionTwo; // <-- need to configure Region depenandcy as "region2props" bean
}
}
Thanks Guys!