来自“Binil Thomas”的评论是正确的,我正在寻找确认Spring的PathMatchingResourcePatternResolver可以从Java Config使用,这样我就可以将生成的“资源”列表提供给Spring Hibernate SessionFactory.mappingLocations,而不必在每次添加新的映射文件时更新Hibernate *.hbm.xml文件的列表。我能够使用以下代码使用PathMatchingResourcePatternResolver来实现这一点:
import org.hibernate.SessionFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
...
ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
Resource [] mappingLocations = patternResolver.getResources("classpath*:mappings/**/*.hbm.xml");
sessionFactory.setMappingLocations(mappingLocations);
像吊饰一样工作。