摘要:異常已解決背景自己寫的博客項目使用使用工具類初始化配置進(jìn)行測試,代碼如下使用加載配置文件生成對應(yīng)的輸入流使用對象加載輸入流工具類初始化配置進(jìn)行測試,代碼如下
自己寫的博客項目使用fastDfs 使用java工具類A初始化fdfs配置進(jìn)行測試,代碼如下
ClassPathResource cpr = new ClassPathResource("fastdfs.properties"); ClientGlobal.init(cpr.getClassLoader().getResource("fdfs_client.conf").toURI().getPath()); Properties properties = new Properties(); // 使用ClassLoader加載properties配置文件生成對應(yīng)的輸入流 InputStream in = cpr.getInputStream(); // 使用properties對象加載輸入流 properties.load(in); ClientGlobal.initByProperties(properties); TrackerGroup trackerGroup = ClientGlobal.g_tracker_group; trackerClient = new TrackerClient(trackerGroup);
工具類B初始化fdfs配置進(jìn)行測試,代碼如下
private static final String CONF_FILENAME = Thread.currentThread().getContextClassLoader() .getResource("fdfs_client.conf").getPath(); -------------------------------------------- ClientGlobal.init(CONF_FILENAME);
java.lang.NullPointerException at java.io.File.(File.java:277) at org.csource.common.IniFileReader.loadFromOsFileSystemOrClasspathAsStream(IniFileReader.java:45) at org.csource.common.IniFileReader.loadFromFile(IniFileReader.java:150) at org.csource.common.IniFileReader.(IniFileReader.java:30) at org.csource.fastdfs.ClientGlobal.init(ClientGlobal.java:91) at com.blog.utils.FastDFSClientUtils.(FastDFSClientUtils.java:51) at com.blog.controller.FastDFSController.upload(FastDFSController.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1064) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1726) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)09:13:42,711 [http-nio-8000-exec-1] ERROR com.blog.utils.FastDFSClientUtils - org.csource.common.MyException: item "tracker_server" in null not found2021-11-24 21:13:42.712 INFO 2498 --- [nio-8000-exec-1] com.blog.controller.FastDFSController : ---文件類型--->jpg09:13:42,714 [http-nio-8000-exec-1] ERROR com.blog.utils.FastDFSClientUtils - java.lang.NullPointerException
不使用讀取配置文件的方法,直接把fdfs的配置寫入工具類進(jìn)行加載
代碼如下
Properties props = new Properties();props.put(ClientGlobal.PROP_KEY_TRACKER_SERVERS,"82.157.172.63:22122");props.put(ClientGlobal.PROP_KEY_CONNECT_TIMEOUT_IN_SECONDS,3);props.put(ClientGlobal.PROP_KEY_NETWORK_TIMEOUT_IN_SECONDS,30);ClientGlobal.initByProperties(props);TrackerClient trackerClient=new TrackerClient();
public class FastDFSClientUtils { private static Logger logger = Logger.getLogger(FastDFSClientUtils.class); private static TrackerClient trackerClient; //加載文件 static { try { //加載fasetdfs配置項 Properties props = new Properties(); props.put(ClientGlobal.PROP_KEY_TRACKER_SERVERS,"82.157.172.63:22122"); props.put(ClientGlobal.PROP_KEY_CONNECT_TIMEOUT_IN_SECONDS,3); props.put(ClientGlobal.PROP_KEY_NETWORK_TIMEOUT_IN_SECONDS,30); ClientGlobal.initByProperties(props); trackerClient=new TrackerClient();// /*第二種init方法 該方法我測試本地可以,服務(wù)器上不行。各位如使用自行測試// ClassPathResource cpr = new ClassPathResource("fastdfs.properties");// ClientGlobal.init(cpr.getClassLoader().getResource("fdfs_client.conf").toURI().getPath());//// Properties properties = new Properties();// // 使用ClassLoader加載properties配置文件生成對應(yīng)的輸入流// InputStream in = cpr.getInputStream();// // 使用properties對象加載輸入流// properties.load(in);// ClientGlobal.initByProperties(properties);//// TrackerGroup trackerGroup = ClientGlobal.g_tracker_group;// trackerClient = new TrackerClient(trackerGroup);//// System.out.println("------>"+trackerClient.getTrackerServer().getInetSocketAddress()); } catch (Exception e) { logger.error(e); } } /** * 方法名稱:上傳方法
* 概要說明:
* @param file 文件 * @param path 路徑 * @return 上傳成功返回id,失敗返回null */ public static String upload(File file, String path) { TrackerServer trackerServer = null; StorageServer storageServer = null; StorageClient1 storageClient1 = null; FileInputStream fis = null; try { NameValuePair[] meta_list = null; // new NameValuePair[0]; fis = new FileInputStream(file); byte[] file_buff = null; if (fis != null) { int len = fis.available(); file_buff = new byte[len]; fis.read(file_buff); } trackerServer = trackerClient.getTrackerServer(); if (trackerServer == null) { logger.error("getConnection return null"); } storageServer = trackerClient.getStoreStorage(trackerServer); storageClient1 = new StorageClient1(trackerServer, storageServer); String fileid = storageClient1.upload_file1(file_buff, getFileExt(path), meta_list); return fileid; } catch (Exception ex) { logger.error(ex); return null; } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { logger.error(e); } } storageClient1 = null; } } /** * 方法名稱:上傳方法
* 概要說明:
* @param data 數(shù)據(jù) * @param extName 路徑 * @return 上傳成功返回id,失敗返回null */ public static String upload(byte[] data, String extName) { TrackerServer trackerServer = null; StorageServer storageServer = null; StorageClient1 storageClient1 = null; try { NameValuePair[] meta_list = null; // new NameValuePair[0]; trackerServer = trackerClient.getTrackerServer(); if (trackerServer == null) { logger.error("getConnection return null"); } storageServer = trackerClient.getStoreStorage(trackerServer); storageClient1 = new StorageClient1(trackerServer, storageServer); String fileid = storageClient1.upload_file1(data, extName, meta_list); return fileid; } catch (Exception ex) { logger.error(ex); return null; } finally { storageClient1 = null; } } /** * 方法名稱:下載方法
* 概要說明:通過文件id進(jìn)行下載
* @param fileId 文件id * @return 返回InputStream */ public static InputStream download(String groupName, String fileId) { TrackerServer trackerServer = null; StorageServer storageServer = null; StorageClient1 storageClient1 = null; try { trackerServer = trackerClient.getTrackerServer(); if (trackerServer == null) { logger.error("getConnection return null"); } storageServer = trackerClient.getStoreStorage(trackerServer, groupName); storageClient1 = new StorageClient1(trackerServer, storageServer); byte[] bytes = storageClient1.download_file1(fileId); InputStream inputStream = new ByteArrayInputStream(bytes); return inputStream; } catch (Exception ex) { logger.error(ex); return null; } finally { storageClient1 = null; } } /** * 方法名稱:刪除方法
* 概要說明:根據(jù)id來刪除一個文件
* @param fileId 文件id * @return 刪除成功返回0,非0則操作失敗,返回錯誤代碼 */ public static int delete(String groupName, String fileId) { TrackerServer trackerServer = null; StorageServer storageServer = null; StorageClient1 storageClient1 = null; try { trackerServer = trackerClient.getTrackerServer(); if (trackerServer == null) { logger.error("getConnection return null"); } storageServer = trackerClient.getStoreStorage(trackerServer, groupName); storageClient1 = new StorageClient1(trackerServer, storageServer); int result = storageClient1.delete_file1(fileId); return result; } catch (Exception ex) { logger.error(ex); return 0; } finally { storageClient1 = null; } } /** * 方法名稱:
* 概要說明:
* @param oldFileId 舊文件id * @param file 新文件 * @param path 新文件路徑 * @ret
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/125286.html
摘要:排列如果所提供的函數(shù)返回的數(shù)量等于數(shù)組中成員數(shù)量的總和,則函數(shù)返回,否則返回。平鋪數(shù)組將數(shù)組降為一維數(shù)組根據(jù)給定的函數(shù)對數(shù)組的元素進(jìn)行分組。使用給定的回調(diào)篩選數(shù)組。相關(guān)文章秒的代碼片段數(shù)學(xué)秒的代碼片段字符串函數(shù) 本文來自GitHub開源項目 點(diǎn)我跳轉(zhuǎn) 30秒的PHP代碼片段 showImg(https://segmentfault.com/img/bVbnR1I?w=2800&h=12...
摘要:父節(jié)點(diǎn)我們可以用方法來獲取某個節(jié)點(diǎn)的父節(jié)點(diǎn),我們用一個實例來感受一下運(yùn)行結(jié)果在這里我們首先用選取了為的節(jié)點(diǎn),然后調(diào)用了方法,得到其父節(jié)點(diǎn),類型依然是類型。 上一篇文章:Python3網(wǎng)絡(luò)爬蟲實戰(zhàn)---29、解析庫的使用:BeautifulSoup下一篇文章:Python3網(wǎng)絡(luò)爬蟲實戰(zhàn)---31、數(shù)據(jù)存儲:文件存儲 在上一節(jié)我們介紹了 BeautifulSoup 的使用,它是一個非常強(qiáng)...
摘要:近期項目用到大量的樹結(jié)構(gòu),比如目錄樹文章標(biāo)記動態(tài)生成樹結(jié)構(gòu),實現(xiàn)的過程是基于的框架,結(jié)合數(shù)據(jù)驅(qū)動應(yīng)用遞歸函數(shù)實現(xiàn)數(shù)據(jù)結(jié)構(gòu)的增刪改查一切思緒的來源,結(jié)合官方提供的樹形圖實例,可以輕松實現(xiàn)自定義開源樹結(jié)構(gòu),上優(yōu)秀的開源插件我都看過,都是基于樹形 近期項目用到大量的樹結(jié)構(gòu),比如目錄樹、文章標(biāo)記動態(tài)生成樹結(jié)構(gòu),實現(xiàn)的過程是基于vue的框架,結(jié)合vue數(shù)據(jù)驅(qū)動應(yīng)用遞歸函數(shù)實現(xiàn)數(shù)據(jù)結(jié)構(gòu)的增刪改查 ...
摘要:概念是根據(jù)的創(chuàng)建的單向數(shù)據(jù)流類庫。的單向數(shù)據(jù)流模式主要由和組成。數(shù)據(jù)更新成功后,還是通過事件機(jī)制傳遞的組件當(dāng)中,并更新。整個過程的對接是通過事件驅(qū)動的。標(biāo)識如果首字母大寫就會識別不了,例如將上面的改成。 概念 Reflux是根據(jù)React的flux創(chuàng)建的單向數(shù)據(jù)流類庫。 Reflux的單向數(shù)據(jù)流模式主要由actions和stores組成。例如,當(dāng)組件list新增item時,會調(diào)用ac...
摘要:汽車之家車型的簡單爬取名字自定義配置重新定義起始爬取點(diǎn)所有首字母按照首字母,組合對應(yīng)的頁面,壓入根據(jù),抓取頁面定義默認(rèn)的抓取函數(shù)品牌編號品牌名品牌品牌小類別品牌小類別對應(yīng)的頁面品牌小類別的編號品牌小類別名品牌小類別對應(yīng)的頁面的 汽車之家車型的簡單爬取spider # -*- coding: utf-8 -*- import scrapy from scrapy import Reque...
閱讀 3801·2023-01-11 11:02
閱讀 4307·2023-01-11 11:02
閱讀 3130·2023-01-11 11:02
閱讀 5238·2023-01-11 11:02
閱讀 4802·2023-01-11 11:02
閱讀 5575·2023-01-11 11:02
閱讀 5379·2023-01-11 11:02
閱讀 4080·2023-01-11 11:02