code: public void scanPackages(String... packagesToScan) throws HibernateException {
          try {
              for (String pkg : packagesToScan) {
                  String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
                          ClassUtils.convertClassNameToResourcePath(pkg) + RESOURCE_PATTERN;
                  Resource[] resources = resourcePatternResolver.getResources(pattern);
                  MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
                  for (Resource resource : resources) {
                      if (resource.isReadable()) {
                          MetadataReader reader = readerFactory.getMetadataReader(resource);
                          String className = reader.getClassMetadata().getClassName();
                          if (matchesFilter(reader, readerFactory)) {
                              Class<?> loadedClass = resourcePatternResolver.getClassLoader().loadClass(className);
                              addAnnotatedClasses(loadedClass);
                          }
                      }
                  }
              }
          }
          catch (IOException ex) {
              throw new MappingException("Failed to scan classpath for unlisted classes", ex);
          }
          catch (ClassNotFoundException ex) {
              throw new MappingException("Failed to load annotated classes from classpath", ex);
          }
      }
docs: Perform Spring-based scanning for entity classes, registering them
  as annotated classes with this {@code Configuration}.
  @param packagesToScan one or more Java package names
  @throws HibernateException if scanning fails for any reason