// Disable xml validation
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setValidating(false);
// Read configuration
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);
reader.setNamespaceAware(true);
reader.loadBeanDefinitions(new ClassPathResource(connection.getPath()));
Properties props = connection.getProperties();
Class<? extends LocalSessionFactoryBean> beanClass = LocalSessionFactoryBean.class;
String beanName = props.getProperty("bean", null);
String beanClassName = props.getProperty("beanClass", null);
if (beanClassName != null) {
beanClass = findClass(beanClassName, beanClass);
}
if (beanName == null) {
throw new IllegalStateException("A 'bean' name is required, matching a '" + beanClassName + "' definition in '" + connection.getPath() + "'.");
}
BeanDefinition beanDef = registry.getBeanDefinition(beanName);
if (beanDef == null) {
throw new IllegalStateException("A bean named '" + beanName + "' could not be found in '" + connection.getPath() + "'.");
}
MutablePropertyValues properties = beanDef.getPropertyValues();