As you're injecting quite a few ResourceBundles using a common approach (I assume you're using the same Locale overall the application) I'd consider using a BeanPostProcessor.
Code:
public class ResourceBundleProcessor implements BeanPostProcessor {
private Locale locale;
public void setLocale(Locale locale) {
this.locale = locale;
}
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
if (bean instanceof ResourceBundleAware) {
ResourceBundleAware awareBean = (ResourceBundleAware) bean;
awareBean.setResourceBundle(
getResourceBundle(bean.getClass().getSimpleName()));
}
return bean;
}
private ResourceBundle getResourceBundle(String baseName) {
// preventing NullPointerExceptions
if (locale == null) {
return ResourceBundle.getBundle(baseName);
} else {
return ResourceBundle.getBundle(baseName, locale);
}
}
}
Code:
public interface ResourceBundleAware {
public void setResourceBundle(ResourceBundle bundle);
}
Code:
public class AssetCustomerResumeReportGenerator
implements ResourceBundleAware {
// ...
}
Code:
<bean id="resourceProcessor" class="x.y.z.ResourceBundleProcessor">
<property name="locale">
<value>es</value>
</property>
</bean>
<bean id="AssetCustomerResumeReportGenerator"
class="com.schinvest.lra.business.report.generator.
xls.AssetCustomerInfo.AssetCustomerResumeReportGenerator"
parent="xlsReportGenerator" singleton="false">
<description>Report generator for AssetCustomerResume</description>
<property name="reportDao">
<ref bean="reportDao"/>
</property>
</bean>
...
greets