/** * Determine the Spring {@link ResourceLoader} to use for Hibernate metadata. * @return the ResourceLoader to use (never {@code null}) * @since 4.3 */ public ResourceLoader getResourceLoader() { if (this.resourcePatternResolver == null) { this.resourcePatternResolver = new PathMatchingResourcePatternResolver(); } return this.resourcePatternResolver; }
/** * Create a new ResourceArrayPropertyEditor with a default * {@link PathMatchingResourcePatternResolver} and {@link StandardEnvironment}. * @see PathMatchingResourcePatternResolver * @see Environment */ public ResourceArrayPropertyEditor() { this(new PathMatchingResourcePatternResolver(), null, true); }
private ResourcePatternResolver getResourcePatternResolver() { if (this.resourcePatternResolver == null) { this.resourcePatternResolver = new PathMatchingResourcePatternResolver(); } return this.resourcePatternResolver; }
public SortedResourcesFactoryBean(List<String> locations) { this.locations = locations; this.resourcePatternResolver = new PathMatchingResourcePatternResolver(); }
/** * Return the ResourcePatternResolver to use for resolving location patterns * into Resource instances. Default is a * {@link org.springframework.core.io.support.PathMatchingResourcePatternResolver}, * supporting Ant-style location patterns. * <p>Can be overridden in subclasses, for extended resolution strategies, * for example in a web environment. * <p><b>Do not call this when needing to resolve a location pattern.</b> * Call the context's {@code getResources} method instead, which * will delegate to the ResourcePatternResolver. * @return the ResourcePatternResolver for this context * @see #getResources * @see org.springframework.core.io.support.PathMatchingResourcePatternResolver */ protected ResourcePatternResolver getResourcePatternResolver() { return new PathMatchingResourcePatternResolver(this); }
/** * Create a new LocalSessionFactoryBuilder for the given DataSource. * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using * (may be {@code null}) */ public LocalSessionFactoryBuilder(@Nullable DataSource dataSource) { this(dataSource, new PathMatchingResourcePatternResolver()); }
/** * Create a new LocalSessionFactoryBuilder for the given DataSource. * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using * (may be {@code null}) * @param classLoader the ClassLoader to load application classes from */ public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ClassLoader classLoader) { this(dataSource, new PathMatchingResourcePatternResolver(classLoader)); }
public ClassPathJaxb2TypeScanner(@Nullable ClassLoader classLoader, String... packagesToScan) { Assert.notEmpty(packagesToScan, "'packagesToScan' must not be empty"); this.resourcePatternResolver = new PathMatchingResourcePatternResolver(classLoader); this.packagesToScan = packagesToScan; }
/** * Return a default ResourcePatternResolver for the given ResourceLoader. * <p>This might be the ResourceLoader itself, if it implements the * ResourcePatternResolver extension, or a PathMatchingResourcePatternResolver * built on the given ResourceLoader. * @param resourceLoader the ResourceLoader to build a pattern resolver for * (may be {@code null} to indicate a default ResourceLoader) * @return the ResourcePatternResolver * @see PathMatchingResourcePatternResolver */ public static ResourcePatternResolver getResourcePatternResolver(@Nullable ResourceLoader resourceLoader) { if (resourceLoader instanceof ResourcePatternResolver) { return (ResourcePatternResolver) resourceLoader; } else if (resourceLoader != null) { return new PathMatchingResourcePatternResolver(resourceLoader); } else { return new PathMatchingResourcePatternResolver(); } }
/** * Takes a resource pattern as (@see org.springframework.core.io.support.PathMatchingResourcePatternResolver) * This allows you load multiple bean resources in this single builder * * eg loadBeans("classpath:*Beans.groovy") * * @param resourcePattern * @throws IOException When the path cannot be matched */ public void loadBeans(String resourcePattern) throws IOException { loadBeans(new PathMatchingResourcePatternResolver().getResources(resourcePattern)); }
@Bean(name = "test2SqlSessionFactory") public SqlSessionFactory testSqlSessionFactory(@Qualifier("test2DataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test2/*.xml")); return bean.getObject(); }
@Test(expected = IllegalArgumentException.class) public void testStrictSystemPropertyReplacement() { PropertyEditor editor = new ResourceArrayPropertyEditor( new PathMatchingResourcePatternResolver(), new StandardEnvironment(), false); System.setProperty("test.prop", "foo"); try { editor.setAsText("${test.prop}-${bar}"); Resource[] resources = (Resource[]) editor.getValue(); assertEquals("foo-${bar}", resources[0].getFilename()); } finally { System.getProperties().remove("test.prop"); } }
@Ignore // not doing schema parsing anymore for JPA 2.0 compatibility @Test public void testNoSchemaPersistence() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-no-schema.xml"; try { reader.readPersistenceUnitInfos(resource); fail("expected invalid document exception"); } catch (RuntimeException expected) { } }
@Ignore // not doing schema parsing anymore for JPA 2.0 compatibility @Test public void testInvalidPersistence() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-invalid.xml"; try { reader.readPersistenceUnitInfos(resource); fail("expected invalid document exception"); } catch (RuntimeException expected) { } }
@Test public void testExample6() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example6.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertEquals(1, info.length); assertEquals("pu", info[0].getPersistenceUnitName()); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
@Test public void testExample2() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example2.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement2", info[0].getPersistenceUnitName()); assertEquals(1, info[0].getMappingFileNames().size()); assertEquals("mappings.xml", info[0].getMappingFileNames().get(0)); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
@Test public void testMetaInfCase() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
@Test public void testExample1() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example1.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement", info[0].getPersistenceUnitName()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
@Test public void testExample5() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example5.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement5", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getMappingFileNames().size()); assertEquals("order1.xml", info[0].getMappingFileNames().get(0)); assertEquals("order2.xml", info[0].getMappingFileNames().get(1)); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals("com.acme.AcmePersistence", info[0].getPersistenceProviderClassName()); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
@Test public void testExample3() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example3.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement3", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals(0, info[0].getProperties().keySet().size()); assertNull(info[0].getJtaDataSource()); assertNull(info[0].getNonJtaDataSource()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }