当前位置: 首页 > news >正文

福田区建设局网站wordpress 点赞数量翻倍

福田区建设局网站,wordpress 点赞数量翻倍,全国旅游景点网站开源,广州哪个大学做网站制作好些的欢迎大家入坑#xff0c;所谓师傅领进坑爬出去靠个人#xff0c;首先我要说的是这个是上一篇《单刀直入ComponentScan》的姊妹篇哈#xff0c;接着把没聊透的事说明白#xff0c;咱不是虎头蛇尾的人。 资源加载是啥意思 scan #xff0c;都认识吧#xff0c;小学词汇连…欢迎大家入坑所谓师傅领进坑爬出去靠个人首先我要说的是这个是上一篇《单刀直入ComponentScan》的姊妹篇哈接着把没聊透的事说明白咱不是虎头蛇尾的人。 资源加载是啥意思 scan 都认识吧小学词汇连我都认识扫到的是啥扫到的是资源啊如何让资源为我所用就需要把资源搞进来这就是资源加载。 spring如何加载资源的 首先不得不承认spring本身是很专一的她把所有的资源都用一个统一的接口来表示Resource,我们不妨看看她的真容。 java /*** Interface for a resource descriptor that abstracts from the actual* type of underlying resource, such as a file or class path resource.** pAn InputStream can be opened for every resource if it exists in* physical form, but a URL or File handle can just be returned for* certain resources. The actual behavior is implementation-specific.** author Juergen Hoeller* since 28.12.2003* see #getInputStream()* see #getURL()* see #getURI()* see #getFile()* see WritableResource* see ContextResource* see UrlResource* see FileUrlResource* see FileSystemResource* see ClassPathResource* see ByteArrayResource* see InputStreamResource*/ public interface Resource extends InputStreamSource {/*** Determine whether this resource actually exists in physical form.* pThis method performs a definitive existence check, whereas the* existence of a {code Resource} handle only guarantees a valid* descriptor handle.*/boolean exists();/*** Indicate whether non-empty contents of this resource can be read via* {link #getInputStream()}.* pWill be {code true} for typical resource descriptors that exist* since it strictly implies {link #exists()} semantics as of 5.1.* Note that actual content reading may still fail when attempted.* However, a value of {code false} is a definitive indication* that the resource content cannot be read.* see #getInputStream()* see #exists()*/default boolean isReadable() {return exists();}/*** Indicate whether this resource represents a handle with an open stream.* If {code true}, the InputStream cannot be read multiple times,* and must be read and closed to avoid resource leaks.* pWill be {code false} for typical resource descriptors.*/default boolean isOpen() {return false;}/*** Determine whether this resource represents a file in a file system.* A value of {code true} strongly suggests (but does not guarantee)* that a {link #getFile()} call will succeed.* pThis is conservatively {code false} by default.* since 5.0* see #getFile()*/default boolean isFile() {return false;}/*** Return a URL handle for this resource.* throws IOException if the resource cannot be resolved as URL,* i.e. if the resource is not available as descriptor*/URL getURL() throws IOException;/*** Return a URI handle for this resource.* throws IOException if the resource cannot be resolved as URI,* i.e. if the resource is not available as descriptor* since 2.5*/URI getURI() throws IOException;/*** Return a File handle for this resource.* throws java.io.FileNotFoundException if the resource cannot be resolved as* absolute file path, i.e. if the resource is not available in a file system* throws IOException in case of general resolution/reading failures* see #getInputStream()*/File getFile() throws IOException;/*** Return a {link ReadableByteChannel}.* pIt is expected that each call creates a ifresh/i channel.* pThe default implementation returns {link Channels#newChannel(InputStream)}* with the result of {link #getInputStream()}.* return the byte channel for the underlying resource (must not be {code null})* throws java.io.FileNotFoundException if the underlying resource doesnt exist* throws IOException if the content channel could not be opened* since 5.0* see #getInputStream()*/default ReadableByteChannel readableChannel() throws IOException {return Channels.newChannel(getInputStream());}/*** Determine the content length for this resource.* throws IOException if the resource cannot be resolved* (in the file system or as some other known physical resource type)*/long contentLength() throws IOException;/*** Determine the last-modified timestamp for this resource.* throws IOException if the resource cannot be resolved* (in the file system or as some other known physical resource type)*/long lastModified() throws IOException;/*** Create a resource relative to this resource.* param relativePath the relative path (relative to this resource)* return the resource handle for the relative resource* throws IOException if the relative resource cannot be determined*/Resource createRelative(String relativePath) throws IOException;/*** Determine a filename for this resource, i.e. typically the last* part of the path: for example, myfile.txt.* pReturns {code null} if this type of resource does not* have a filename.*/NullableString getFilename();/*** Return a description for this resource,* to be used for error output when working with the resource.* pImplementations are also encouraged to return this value* from their {code toString} method.* see Object#toString()*/String getDescription();}请原谅我用代码占用了很大的篇幅主要是为了让大家通过看文章不用去翻代码能够连贯的读下来同时没有把注释去掉的原因是任何只看代码不看注释的行为都是耍流氓多说一句我觉得想要成为快乐的程序员应该具备勇气和丰富的想象力。以上内容就需要你的想象力了我啥都不说了。要用心别走马观花看热闹觉得挺热闹然后给个赞对自己啥收获也没有那就是浪费时间这是一个浪费了10余年老程序员的忠告虽然现在他依然在浪费着时间写到这里感觉自己有点飘了呢开始好为人师了。 接下来着重说一下Resource的神兵利器ResourceLoader 她算一个重头戏资源加载器拿来加载资源为什么要有这么个东东呢要根据她在spring中唯一的实现 DefaultResourceLoader 说起。 public class DefaultResourceLoader implements ResourceLoader {Nullableprivate ClassLoader classLoader;private final SetProtocolResolver protocolResolvers new LinkedHashSet(4);private final MapClass?, MapResource, ? resourceCaches new ConcurrentHashMap(4);~~~~~~~~~~~~~~/*** Register the given resolver with this resource loader, allowing for* additional protocols to be handled.* pAny such resolver will be invoked ahead of this loaders standard* resolution rules. It may therefore also override any default rules.* since 4.3* see #getProtocolResolvers()*/public void addProtocolResolver(ProtocolResolver resolver) {Assert.notNull(resolver, ProtocolResolver must not be null);this.protocolResolvers.add(resolver);}Overridepublic Resource getResource(String location) {Assert.notNull(location, Location must not be null);for (ProtocolResolver protocolResolver : getProtocolResolvers()) {Resource resource protocolResolver.resolve(location, this);if (resource ! null) {return resource;}}if (location.startsWith(/)) {return getResourceByPath(location);}else if (location.startsWith(CLASSPATH_URL_PREFIX)) {return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());}else {try {// Try to parse the location as a URL...URL url new URL(location);return (ResourceUtils.isFileURL(url) ? new FileUrlResource(url) : new UrlResource(url));}catch (MalformedURLException ex) {// No URL - resolve as resource path.return getResourceByPath(location);}}} 不好意思上面的类代码是不完整的我删除了一些简单的构造函数还有一些我没看懂的复杂函数捡我认为重要的说Resource getResource(String location)这核心的方法也揭秘了ResourceLoader 存在的价值首先我们知道我们在加载自愿的时候资源的形态是多样的这个通过上面的注释也能看出来有 UrlResource FileUrlResource FileSystemResource ClassPathResourceResourceLoader 的作用就是可以让多样的资源来源加载用统一的方法来加载主要是根据资源加载路径的组成方式比如d:\abc.txt,www.baidu.com/abc.txt,classpath:abc.class, getResouce方法其实使用简单工厂模式的方式。public void addProtocolResolver(ProtocolResolver resolver) 这个方法其实是留给我们使用者去进行扩展的当你的资源加载方式比较复杂比如你的资源路径是通过读取另一些资源来拼装的那么你可以自定义ProtocolResolver 来处理因为getRource方法的第一句就是 for (ProtocolResolver protocolResolver : getProtocolResolvers()) {Resource resource protocolResolver.resolve(location, this);if (resource ! null) {return resource;}}如何去注册自己的ProtocolResolver 呢applicationContext.addProtocolResolver();奥秘就是因为public abstract class AbstractApplicationContext extends DefaultResourceLoader。 如果你耐心的读到这里我必须上点干货了报答你的不走之恩。 ComponentScan 是如何应用这个ResourceLoader 的呢ConfigurationClassPostProcessor 这个重头类就必须要说一下了她是干嘛地…! 不得不说她是一个牛逼的类干的事特别的多。 解析 Configuration。解析 Bean 方法。解析 ComponentScan。解析 Import 注解。解析 ImportResource 注解。解析 PropertySource 注解。 可以这样说所有bean的加载都是他来干她实现了BeanDefinitionRegistryPostProcessor懂得都懂然后有一个关键台词类里有一个成员变量private ResourceLoader resourceLoader new DefaultResourceLoader(); 然后把这个成员变量向下传递一直到上文说到的private Set scanCandidateComponents(String basePackage)方法中哈找到潜在的组件什么组件无非就是上文说的加了Component Service Controller等注解的类呗。 private SetBeanDefinition scanCandidateComponents(String basePackage) {SetBeanDefinition candidates new LinkedHashSet();try {String packageSearchPath ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX resolveBasePackage(basePackage) / this.resourcePattern;**Resource[] resources getResourcePatternResolver().getResources(packageSearchPath);**boolean traceEnabled logger.isTraceEnabled();boolean debugEnabled logger.isDebugEnabled();for (Resource resource : resources) {if (traceEnabled) {logger.trace(Scanning resource);}if (resource.isReadable()) {try {MetadataReader metadataReader getMetadataReaderFactory().getMetadataReader(resource);if (isCandidateComponent(metadataReader)) {ScannedGenericBeanDefinition sbd new ScannedGenericBeanDefinition(metadataReader);sbd.setResource(resource);sbd.setSource(resource);if (isCandidateComponent(sbd)) {if (debugEnabled) {logger.debug(Identified candidate component class: resource);}candidates.add(sbd);}else {if (debugEnabled) {logger.debug(Ignored because not a concrete top-level class: resource);}}}else {if (traceEnabled) {logger.trace(Ignored because not matching any filter: resource);}}}catch (Throwable ex) {throw new BeanDefinitionStoreException(Failed to read candidate component class: resource, ex);}}else {if (traceEnabled) {logger.trace(Ignored because not readable: resource);}}}}catch (IOException ex) {throw new BeanDefinitionStoreException(I/O failure during classpath scanning, ex);}return candidates; }两句关键台词 String packageSearchPath ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX resolveBasePackage(basePackage) ‘/’ this.resourcePattern; Resource[] resources getResourcePatternResolver().getResources(packageSearchPath); 细心的读者会发现我们一直说的ResourceLoader 接口里面就没有getResources方法这里面就提到一个衍生的接口ResourcePatternResolver。 public interface ResourcePatternResolver extends ResourceLoader {/*** Pseudo URL prefix for all matching resources from the class path: classpath*:* This differs from ResourceLoaders classpath URL prefix in that it* retrieves all matching resources for a given name (e.g. /beans.xml),* for example in the root of all deployed JAR files.* see org.springframework.core.io.ResourceLoader#CLASSPATH_URL_PREFIX*/String CLASSPATH_ALL_URL_PREFIX classpath*:;/*** Resolve the given location pattern into Resource objects.* pOverlapping resource entries that point to the same physical* resource should be avoided, as far as possible. The result should* have set semantics.* param locationPattern the location pattern to resolve* return the corresponding Resource objects* throws IOException in case of I/O errors*/Resource[] getResources(String locationPattern) throws IOException; } getResourcePatternResolver 获取到的是PathMatchingResourcePatternResolver处理器然后通过循环调用defaultResourceLoader的getResource方法来加载资源。今天先说这么多吧对于加载还有不少内容不放在一起了以防都看蒙圈了。下一篇会着重讲下这里面的内容。
http://www.hkea.cn/news/14356381/

相关文章:

  • 缩短链接的网站做企业平台网站成本
  • 做网站的公司应该做收录嘛微信小程序做直播网站
  • 网站开发书的案例北京网络营销公司网页
  • 绵竹移动网站建设网站建设开题报告设计
  • 长沙网站seo公司国外外贸平台
  • 购物网站后台管理模板淘宝客商品推广网站建设
  • 网站平台推广方案东莞好的网站国外站建设价格
  • wordpress响应式主板成都网站快速优化排名
  • 建设音乐主题网站海口网站建设好
  • 哈尔滨网站开发海南网站开发公司
  • 新宫网站建设公司泉州建站软件
  • 沈阳网站建设公司app开发价格公司
  • 网站建设后端工程师岗位职责做网站网
  • 网站建设制作软件建设项目信息类网站
  • asp网站怎么改成中英双语泊头哪里有做网站的
  • 网站建设的电话销售聚企网
  • 丰台广州网站建设平罗县住房和城乡建设局网站
  • 建设系统网站全名建筑模板尺寸是多少
  • 温州网站开发网站的制作网页设计作业制作个人网站
  • 第一模板网站上的模板怎么下载沈阳网站制作优化推广
  • 免费建立个人app网站大兴安岭地网站seo
  • 建设部门户网站电子商务网站制作步骤
  • 新建网站推广凌美上海建设工程网站
  • 汶上网站建设哪家好wordpress 高亮
  • 微信app网站建设吉林省建设信息管理平台
  • 网站空间要备案吗d?t网站模版
  • 东莞个人网站建设体育新闻最新消息
  • 做搞笑app好还是做电影网站好东莞常平健明眼科医院
  • 营销型网站建设电子书吉祥又聚财的公司名字
  • 网站设计自学seo网络推广员招聘