本文整理了Java中org.springframework.context.ApplicationContext.getResource()
方法的一些代码示例,展示了ApplicationContext.getResource()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContext.getResource()
方法的具体详情如下:
包路径:org.springframework.context.ApplicationContext
类名称:ApplicationContext
方法名:getResource
暂无
代码示例来源:origin: Red5/red5-server
/**
* Return resource by path
*
* @param path
* Resource path
* @return Resource
*
* @see org.springframework.core.io.Resource
*/
public Resource getResource(String path) {
return applicationContext.getResource(contextPath + path);
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
protected Resource getResource(String location) {
if (this.resourceLoaderPaths != null) {
for (String path : this.resourceLoaderPaths) {
Resource resource = obtainApplicationContext().getResource(path + location);
if (resource.exists()) {
return resource;
}
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
protected Resource getResource(String location) {
if (this.resourceLoaderPaths != null) {
for (String path : this.resourceLoaderPaths) {
Resource resource = obtainApplicationContext().getResource(path + location);
if (resource.exists()) {
return resource;
}
}
}
return null;
}
代码示例来源:origin: redisson/redisson
private InputStream getConfigStream() throws IOException {
Resource resource = ctx.getResource(redissonProperties.getConfig());
InputStream is = resource.getInputStream();
return is;
}
代码示例来源:origin: org.springframework/spring-webmvc
@Nullable
protected Resource getResource(String location) {
if (this.resourceLoaderPaths != null) {
for (String path : this.resourceLoaderPaths) {
Resource resource = obtainApplicationContext().getResource(path + location);
if (resource.exists()) {
return resource;
}
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Read the raw PDF resource into an iText PdfReader.
* <p>The default implementation resolve the specified "url" property
* as ApplicationContext resource.
* @return the PdfReader instance
* @throws IOException if resource access failed
* @see #setUrl
*/
protected PdfReader readPdfResource() throws IOException {
String url = getUrl();
Assert.state(url != null, "'url' not set");
return new PdfReader(obtainApplicationContext().getResource(url).getInputStream());
}
代码示例来源:origin: spring-projects/spring-framework
location = location.substring(endIndex + 1);
Resource resource = applicationContext.getResource(location);
this.locations.add(resource);
if (charset != null) {
代码示例来源:origin: spring-projects/spring-framework
/**
* Get the XSLT {@link Source} for the XSLT template under the {@link #setUrl configured URL}.
* @return the Source object
*/
protected Source getStylesheetSource() {
String url = getUrl();
Assert.state(url != null, "'url' not set");
if (logger.isDebugEnabled()) {
logger.debug("Applying stylesheet [" + url + "]");
}
try {
Resource resource = obtainApplicationContext().getResource(url);
return new StreamSource(resource.getInputStream(), resource.getURI().toASCIIString());
}
catch (IOException ex) {
throw new ApplicationContextException("Can't load XSLT stylesheet from '" + url + "'", ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Execute the given SQL script.
* <p>Use with caution outside of a transaction!
* <p>The script will normally be loaded by classpath.
* <p><b>Do not use this method to execute DDL if you expect rollback.</b>
* @param sqlResourcePath the Spring resource path for the SQL script
* @param continueOnError whether or not to continue without throwing an
* exception in the event of an error
* @throws DataAccessException if there is an error executing a statement
* @see ResourceDatabasePopulator
* @see #setSqlScriptEncoding
*/
protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException {
DataSource ds = this.jdbcTemplate.getDataSource();
Assert.state(ds != null, "No DataSource set");
Assert.state(this.applicationContext != null, "No ApplicationContext set");
Resource resource = this.applicationContext.getResource(sqlResourcePath);
new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(ds);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Execute the given SQL script.
* <p>Use with caution outside of a transaction!
* <p>The script will normally be loaded by classpath.
* <p><b>Do not use this method to execute DDL if you expect rollback.</b>
* @param sqlResourcePath the Spring resource path for the SQL script
* @param continueOnError whether or not to continue without throwing an
* exception in the event of an error
* @throws DataAccessException if there is an error executing a statement
* @see ResourceDatabasePopulator
* @see #setSqlScriptEncoding
*/
protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException {
DataSource ds = this.jdbcTemplate.getDataSource();
Assert.state(ds != null, "No DataSource set");
Assert.state(this.applicationContext != null, "No ApplicationContext available");
Resource resource = this.applicationContext.getResource(sqlResourcePath);
new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(ds);
}
代码示例来源:origin: spring-projects/spring-security
private void importLdif(InMemoryDirectoryServer directoryServer) {
if (StringUtils.hasText(this.ldif)) {
Resource resource = this.context.getResource(this.ldif);
try {
if (resource.exists()) {
try (InputStream inputStream = resource.getInputStream()) {
directoryServer.importFromLDIF(false, new LDIFReader(inputStream));
}
}
} catch (Exception ex) {
throw new IllegalStateException("Unable to load LDIF " + this.ldif, ex);
}
}
}
代码示例来源:origin: org.springframework/spring-webmvc
/**
* Read the raw PDF resource into an iText PdfReader.
* <p>The default implementation resolve the specified "url" property
* as ApplicationContext resource.
* @return the PdfReader instance
* @throws IOException if resource access failed
* @see #setUrl
*/
protected PdfReader readPdfResource() throws IOException {
String url = getUrl();
Assert.state(url != null, "'url' not set");
return new PdfReader(obtainApplicationContext().getResource(url).getInputStream());
}
代码示例来源:origin: spring-projects/spring-framework
protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException {
Resource resource = this.applicationContext.getResource(sqlResourcePath);
new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(jdbcTemplate.getDataSource());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Initialize the view bean factory from the XML file.
* Synchronized because of access by parallel threads.
* @throws BeansException in case of initialization errors
*/
protected synchronized BeanFactory initFactory() throws BeansException {
if (this.cachedFactory != null) {
return this.cachedFactory;
}
ApplicationContext applicationContext = obtainApplicationContext();
Resource actualLocation = this.location;
if (actualLocation == null) {
actualLocation = applicationContext.getResource(DEFAULT_LOCATION);
}
// Create child ApplicationContext for views.
GenericWebApplicationContext factory = new GenericWebApplicationContext();
factory.setParent(applicationContext);
factory.setServletContext(getServletContext());
// Load XML resource with context-aware entity resolver.
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.setEnvironment(applicationContext.getEnvironment());
reader.setEntityResolver(new ResourceEntityResolver(applicationContext));
reader.loadBeanDefinitions(actualLocation);
factory.refresh();
if (isCache()) {
this.cachedFactory = factory;
}
return factory;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void missingDataSourceAndTxMgr() throws Exception {
ApplicationContext ctx = mock(ApplicationContext.class);
given(ctx.getResource(anyString())).willReturn(mock(Resource.class));
given(ctx.getAutowireCapableBeanFactory()).willReturn(mock(AutowireCapableBeanFactory.class));
Class<?> clazz = MissingDataSourceAndTxMgr.class;
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("foo"));
given(testContext.getApplicationContext()).willReturn(ctx);
assertExceptionContains("supply at least a DataSource or PlatformTransactionManager");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void isolatedTxModeDeclaredWithoutTxMgr() throws Exception {
ApplicationContext ctx = mock(ApplicationContext.class);
given(ctx.getResource(anyString())).willReturn(mock(Resource.class));
given(ctx.getAutowireCapableBeanFactory()).willReturn(mock(AutowireCapableBeanFactory.class));
Class<?> clazz = IsolatedWithoutTxMgr.class;
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("foo"));
given(testContext.getApplicationContext()).willReturn(ctx);
assertExceptionContains("cannot execute SQL scripts using Transaction Mode [ISOLATED] without a PlatformTransactionManager");
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testSaveStateDisabled() throws Exception {
this.ldifReader = new LdifReaderBuilder().saveState(false).resource(context.getResource("classpath:/test.ldif"))
.build();
ExecutionContext executionContext = new ExecutionContext();
firstRead(executionContext);
this.ldifReader.update(executionContext);
assertEquals("ExecutionContext should have been empty", 0, executionContext.size());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testSkipRecord() throws Exception {
this.ldifReader = new LdifReaderBuilder().recordsToSkip(1).resource(context.getResource("classpath:/test.ldif"))
.name("foo").build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("The attribute name for the second record did not match expected result",
"cn=Bjorn Jensen, ou=Accounting, dc=airius, dc=com", ldapAttributes.getName().toString());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testBasicRead() throws Exception {
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>()
.recordMapper(new TestMapper())
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("The attribute name for the first record did not match expected result",
"cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com", ldapAttributes.getName().toString());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testMaxItemCount() throws Exception {
this.ldifReader = new LdifReaderBuilder().maxItemCount(1).resource(context.getResource("classpath:/test.ldif"))
.name("foo").build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("The attribute name for the first record did not match expected result",
"cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com", ldapAttributes.getName().toString());
ldapAttributes = this.ldifReader.read();
assertNull("The second read should have returned null", ldapAttributes);
}
内容来源于网络,如有侵权,请联系作者删除!