Spring 零碎整理 以后自己用的到
来源:互联网 发布:微商和淘宝哪个东西贵 编辑:程序博客网 时间:2024/06/01 09:02
明确注册一个BeanFactoryPostProcessor使用BeanFactory实现时,您必须编写代码如下:
XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource("beans.xml"));// bring in some property values from a Properties filePropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();cfg.setLocation(new FileSystemResource("jdbc.properties"));// now actually do the replacementcfg.postProcessBeanFactory(factory);
The ResourceLoader
The ResourceLoader
interface is meant to be implemented by objects that can return (i.e. load) Resource
instances.
public interface ResourceLoader { Resource getResource(String location);}
All application contexts implement the ResourceLoader
interface, and therefore all application contexts may be used to obtain Resource
instances.
When you call getResource()
on a specific application context, and the location path specified doesn’t have a specific prefix, you will get back a Resource
type that is appropriate to that particular application context. For example, assume the following snippet of code was executed against a ClassPathXmlApplicationContext
instance:
Resource template = ctx.getResource("some/resource/path/myTemplate.txt");
What would be returned would be a ClassPathResource
; if the same method was executed against a FileSystemXmlApplicationContext
instance, you’d get back aFileSystemResource
. For a WebApplicationContext
, you’d get back a ServletContextResource
, and so on.
As such, you can load resources in a fashion appropriate to the particular application context.
On the other hand, you may also force ClassPathResource
to be used, regardless of the application context type, by specifying the special classpath:
prefix:
Resource template = ctx.getResource("classpath:some/resource/path/myTemplate.txt");
Similarly, one can force a UrlResource
to be used by specifying any of the standard java.net.URL
prefixes:
Resource template = ctx.getResource("file:/some/resource/path/myTemplate.txt");
Resource template = ctx.getResource("http://myhost.com/resource/path/myTemplate.txt");
The following table summarizes the strategy for converting String
s to Resource
s:
Table 5.1. Resource strings
classpath:
classpath:com/myapp/config.xml
Loaded from the classpath.
file:
file:/data/config.xml
Loaded as a URL
, from the filesystem. [1]
http:
http://myserver/logo.png
Loaded as a URL
.
(none)
/data/config.xml
Depends on the underlying ApplicationContext
.
[1] But see also Section 5.7.3, “FileSystemResource caveats”.
- Spring 零碎整理 以后自己用的到
- 一些零碎的整理
- spring security 自己的整理
- 自己攒的一些函数,希望以后 可以用的到。
- assign的用法,自己收藏,以后可能用的到
- 以后自己用的Excel批量导入
- 以后自己用的Excel批量导出
- 零碎整理
- 以后自己的规范~~
- 以后自己看的
- 写给以后的自己
- sql语句整合_自己以后整理
- 关于android的零碎问题的整理
- iOS中一些零碎的整理
- js中零碎点的整理
- 零碎的知识点(未整理)
- oracle 整理的小零碎2
- 关于list的零碎知识整理
- ouih gtjt4
- dgyu igghv5
- WordDetailScreen
- dgyu igghv5
- ADC 相关
- Spring 零碎整理 以后自己用的到
- MySQL查询优化-explain
- vdsm(1)安装
- PAT 1004. Counting Leaves (30)
- 学习笔记 Java_毕向东_语言基础_程序流程控制 2014.7.29
- cocos2d-x 3.0游戏实例学习笔记 《跑酷》第四步--地图循环&主角添加动作
- 减税:牛市的真正号角与中国经济逃生之门
- POJ 1258-Agri-Net(最小生成树prim)
- word list 16 to 18