资讯专栏INFORMATION COLUMN

org.csource.common.MyException: item “tracker_serv

不知名网友 / 1512人阅读

摘要:异常已解决背景自己写的博客项目使用使用工具类初始化配置进行测试,代码如下使用加载配置文件生成对应的输入流使用对象加载输入流工具类初始化配置进行测试,代码如下

org.csource.common.MyException: item “tracker_server” in null not found异常已解决

背景

自己写的博客项目使用fastDfs 使用java工具类A初始化fdfs配置进行测试,代码如下

			ClassPathResource cpr = new ClassPathResource("fastdfs.properties");			ClientGlobal.init(cpr.getClassLoader().getResource("fdfs_client.conf").toURI().getPath());			Properties properties = new Properties();			// 使用ClassLoader加载properties配置文件生成对应的输入流			InputStream in = cpr.getInputStream();			// 使用properties对象加载输入流			properties.load(in);			ClientGlobal.initByProperties(properties);			TrackerGroup trackerGroup = ClientGlobal.g_tracker_group;			trackerClient = new TrackerClient(trackerGroup);

工具类B初始化fdfs配置进行测试,代码如下

private static final String CONF_FILENAME = Thread.currentThread().getContextClassLoader()			.getResource("fdfs_client.conf").getPath();			--------------------------------------------			ClientGlobal.init(CONF_FILENAME);

使用这两种方式都是去读取配置文件fdfs_client.conf,但是本地都正常,服务器上(CentOS7.6)不行,报错内容如下

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

主要报错内容 org.csource.common.MyException: item “tracker_server” in null not found

解决办法

不使用读取配置文件的方法,直接把fdfs的配置写入工具类进行加载
代码如下

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方法  该方法我测试本地可以,服务器上不行。各位如使用自行测试//			ClassPathResource cpr = new ClassPathResource("fastdfs.properties");//			ClientGlobal.init(cpr.getClassLoader().getResource("fdfs_client.conf").toURI().getPath());////			Properties properties = new Properties();//			// 使用ClassLoader加载properties配置文件生成对应的输入流//			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 数据 * @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进行下载
* @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; } } /** * 方法名称:删除方法
* 概要说明:根据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

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/125286.html

相关文章

  • 30秒的PHP代码片段(1)数组 - Array

    摘要:排列如果所提供的函数返回的数量等于数组中成员数量的总和,则函数返回,否则返回。平铺数组将数组降为一维数组根据给定的函数对数组的元素进行分组。使用给定的回调筛选数组。相关文章秒的代码片段数学秒的代码片段字符串函数 本文来自GitHub开源项目 点我跳转 30秒的PHP代码片段 showImg(https://segmentfault.com/img/bVbnR1I?w=2800&h=12...

    dunizb 评论0 收藏0
  • Python3网络爬虫实战---30、解析库的使用:PyQuery

    摘要:父节点我们可以用方法来获取某个节点的父节点,我们用一个实例来感受一下运行结果在这里我们首先用选取了为的节点,然后调用了方法,得到其父节点,类型依然是类型。 上一篇文章:Python3网络爬虫实战---29、解析库的使用:BeautifulSoup下一篇文章:Python3网络爬虫实战---31、数据存储:文件存储 在上一节我们介绍了 BeautifulSoup 的使用,它是一个非常强...

    IntMain 评论0 收藏0
  • Javascript js递归函数 树结构

    摘要:近期项目用到大量的树结构,比如目录树文章标记动态生成树结构,实现的过程是基于的框架,结合数据驱动应用递归函数实现数据结构的增删改查一切思绪的来源,结合官方提供的树形图实例,可以轻松实现自定义开源树结构,上优秀的开源插件我都看过,都是基于树形 近期项目用到大量的树结构,比如目录树、文章标记动态生成树结构,实现的过程是基于vue的框架,结合vue数据驱动应用递归函数实现数据结构的增删改查 ...

    junbaor 评论0 收藏0
  • React Reflux

    摘要:概念是根据的创建的单向数据流类库。的单向数据流模式主要由和组成。数据更新成功后,还是通过事件机制传递的组件当中,并更新。整个过程的对接是通过事件驱动的。标识如果首字母大写就会识别不了,例如将上面的改成。 概念 Reflux是根据React的flux创建的单向数据流类库。 Reflux的单向数据流模式主要由actions和stores组成。例如,当组件list新增item时,会调用ac...

    ormsf 评论0 收藏0
  • scrapy汽车之家车型的简单爬取

    摘要:汽车之家车型的简单爬取名字自定义配置重新定义起始爬取点所有首字母按照首字母,组合对应的页面,压入根据,抓取页面定义默认的抓取函数品牌编号品牌名品牌品牌小类别品牌小类别对应的页面品牌小类别的编号品牌小类别名品牌小类别对应的页面的 汽车之家车型的简单爬取spider # -*- coding: utf-8 -*- import scrapy from scrapy import Reque...

    zhangfaliang 评论0 收藏0

发表评论

0条评论

不知名网友

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<