Java基础、中级、高级、架构面试资料

解决 elasticsearch ik analyzer access denied “java.io.FilePermission”

JAVA herman 6489浏览 0评论
公告:“业余草”微信公众号提供免费CSDN下载服务(只下Java资源),关注业余草微信公众号,添加作者微信:xttblog2,发送下载链接帮助你免费下载!
本博客日IP超过2000,PV 3000 左右,急需赞助商。
极客时间所有课程通过我的二维码购买后返现24元微信红包,请加博主新的微信号:xttblog2,之前的微信号好友位已满,备注:返现
受密码保护的文章请关注“业余草”公众号,回复关键字“0”获得密码
所有面试题(java、前端、数据库、springboot等)一网打尽,请关注文末小程序
视频教程免费领
腾讯云】1核2G5M轻量应用服务器50元首年,高性价比,助您轻松上云

今天在使用 elasticsearch 的中文分词时,遇到了 access denied 问题。抛出的异常大概是 java.io.FilePermission,即权限问题。整个异常信息如下:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'blogController': Unsatisfied dependency expressed through field 'esBlogService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'esBlogServiceImpl': Unsatisfied dependency expressed through field 'esBlogRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'esBlogRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is java.lang.SecurityException: access denied ("java.io.FilePermission" "D:\Program%20Files\elasticsearch-6.2.4\plugins\analysis-ik\config\IKAnalyzer.cfg.xml" "read")

从异常提示信息上看是权限问题,就是说 IKAnalyzer.cfg.xml 这个文件,java 程序只有读取权限,而对于 IKAnalyzer.cfg.xml 文件,elasticsearch 程序代码可能还需求其他一些权限,所以不能只有读权限。

然后我对 IKAnalyzer.cfg.xml 文件设置了非只读属性后,发现马上又变成了只读属性。最终原因是因为 D:\Program Files文件夹下的都是默认的只读权限。我把 elasticsearch-6.2.4 直接放在 D 盘然后重启 elasticsearch 后,程序就不在出这个错误了。

业余草公众号

最后,欢迎关注我的个人微信公众号:业余草(yyucao)!可加作者微信号:xttblog2。备注:“1”,添加博主微信拉你进微信群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作也可添加作者微信进行联系!

本文原文出处:业余草: » 解决 elasticsearch ik analyzer access denied “java.io.FilePermission”