本文整理匯總了Java中org.springframework.core.io.Resource.getURL方法的典型用法代碼示例。如果您正苦於以下問題:Java Resource.getURL方法的具體用法?Java Resource.getURL怎麽用?Java Resource.getURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.core.io.Resource
的用法示例。
在下文中一共展示了Resource.getURL方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hazelcastInstance
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* Hazelcast instance that is used by the spring session
* repository to broadcast session events. The name
* of this bean must be left untouched.
*
* @return the hazelcast instance
*/
@Bean
public HazelcastInstance hazelcastInstance() {
final Resource hzConfigResource = casProperties.getWebflow().getSession().getHzLocation();
try {
final URL configUrl = hzConfigResource.getURL();
final Config config = new XmlConfigBuilder(hzConfigResource.getInputStream()).build();
config.setConfigurationUrl(configUrl);
config.setInstanceName(this.getClass().getSimpleName())
.setProperty("hazelcast.logging.type", "slf4j")
.setProperty("hazelcast.max.no.heartbeat.seconds", "300");
return Hazelcast.newHazelcastInstance(config);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
示例2: determineDefaultPersistenceUnitRootUrl
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* Try to determine the persistence unit root URL based on the given
* "defaultPersistenceUnitRootLocation".
* @return the persistence unit root URL to pass to the JPA PersistenceProvider
* @see #setDefaultPersistenceUnitRootLocation
*/
private URL determineDefaultPersistenceUnitRootUrl() {
if (this.defaultPersistenceUnitRootLocation == null) {
return null;
}
try {
Resource res = this.resourcePatternResolver.getResource(this.defaultPersistenceUnitRootLocation);
return res.getURL();
}
catch (IOException ex) {
throw new PersistenceException("Unable to resolve persistence unit root URL", ex);
}
}
示例3: determinePersistenceUnitRootUrl
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* Determine the persistence unit root URL based on the given resource
* (which points to the {@code persistence.xml} file we're reading).
* @param resource the resource to check
* @return the corresponding persistence unit root URL
* @throws IOException if the checking failed
*/
protected URL determinePersistenceUnitRootUrl(Resource resource) throws IOException {
URL originalURL = resource.getURL();
// If we get an archive, simply return the jar URL (section 6.2 from the JPA spec)
if (ResourceUtils.isJarURL(originalURL)) {
return ResourceUtils.extractJarFileURL(originalURL);
}
// check META-INF folder
String urlToString = originalURL.toExternalForm();
if (!urlToString.contains(META_INF)) {
if (logger.isInfoEnabled()) {
logger.info(resource.getFilename() +
" should be located inside META-INF directory; cannot determine persistence unit root URL for " +
resource);
}
return null;
}
if (urlToString.lastIndexOf(META_INF) == urlToString.lastIndexOf('/') - (1 + META_INF.length())) {
if (logger.isInfoEnabled()) {
logger.info(resource.getFilename() +
" is not located in the root of META-INF directory; cannot determine persistence unit root URL for " +
resource);
}
return null;
}
String persistenceUnitRoot = urlToString.substring(0, urlToString.lastIndexOf(META_INF));
if (persistenceUnitRoot.endsWith("/")) {
persistenceUnitRoot = persistenceUnitRoot.substring(0, persistenceUnitRoot.length() - 1);
}
return new URL(persistenceUnitRoot);
}
示例4: buildDefaultPersistenceUnitInfo
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* Perform Spring-based scanning for entity classes.
* @see #setPackagesToScan
*/
private SpringPersistenceUnitInfo buildDefaultPersistenceUnitInfo() {
SpringPersistenceUnitInfo scannedUnit = new SpringPersistenceUnitInfo();
scannedUnit.setPersistenceUnitName(this.defaultPersistenceUnitName);
scannedUnit.setExcludeUnlistedClasses(true);
if (this.packagesToScan != null) {
for (String pkg : this.packagesToScan) {
try {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
ClassUtils.convertClassNameToResourcePath(pkg) + ENTITY_CLASS_RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
if (matchesFilter(reader, readerFactory)) {
scannedUnit.addManagedClassName(className);
if (scannedUnit.getPersistenceUnitRootUrl() == null) {
URL url = resource.getURL();
if (ResourceUtils.isJarURL(url)) {
scannedUnit.setPersistenceUnitRootUrl(ResourceUtils.extractJarFileURL(url));
}
}
}
}
}
}
catch (IOException ex) {
throw new PersistenceException("Failed to scan classpath for unlisted entity classes", ex);
}
}
}
if (this.mappingResources != null) {
for (String mappingFileName : this.mappingResources) {
scannedUnit.addMappingFileName(mappingFileName);
}
}
else if (useOrmXmlForDefaultPersistenceUnit()) {
scannedUnit.addMappingFileName(DEFAULT_ORM_XML_RESOURCE);
}
return scannedUnit;
}
示例5: setWsdlDocumentResource
import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
* Set the WSDL document URL as a {@link Resource}.
* @throws IOException
* @since 3.2
*/
public void setWsdlDocumentResource(Resource wsdlDocumentResource) throws IOException {
Assert.notNull(wsdlDocumentResource, "WSDL Resource must not be null.");
this.wsdlDocumentUrl = wsdlDocumentResource.getURL();
}