It’s very simple everything of xml configuration is replaced with annotations.
Remove xml file.
Replace xml with configuration java class.
@configuration annotation
This is just to inform where our configuration is placed like beans and properties file.
@bean annotation
Same as xml this will return objects
See below samples:
@Bean
Merchant merchantBean() {
return new Merchant();
}
// This will return Merchant object and client invokes as
Merchant merchant = context.getBean(Merchant.class);
@Bean({"m1", "m2"})
Merchant merchantBeans() {
return new Merchant();
}
// This will return Merchant object and client invokes as
Merchant merchant = context.getBean(“m1”);
Merchant merchant1 = context.getBean(“m2”);
@propertySource : To specify property file path in xml we used to use PropertyPlaceholderConfigurer class this is achieved by annotations.
@Configuration
@PropertySource(value = { "data.properties" })
public class ConfigClass {
}
// This will return values for any variable as an injection as below
@Value("${data.merchId}")
int merchantId;
@Value("${data.legalBusinessName}")
String legalBusinessName;