本文整理汇总了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();
}