打成jar百度的富文本就会出现这个问题
本地环境不会,上了测试机就会,是读取不到后台配置信息造成的
controller.jsp这个文件读取不到项目的真实路径,遇到同样问题的人可以打下log看下
所以这种情况我们只能在后台去写控制器去实现,因为打成jar包后他的路径跟war包是不一样的
他放在BOOT-INF这个文件夹里面,读取不到的
解决方案:
把json文件放到这里
然后后台写个kongzhi
@Controller public class UEditorConfig { @Value(value="classpath:config.json") private Resource resource; @GetMapping("/ueconfig") public void getUEConfig(HttpServletRequest request, HttpServletResponse response){ org.springframework.core.io.Resource res = new ClassPathResource("config.json"); response.setHeader("Content-Type" , "text/html"); try { BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream())); StringBuffer message=new StringBuffer(); String line = null; while((line = br.readLine()) != null) { message.append(line); } String result = message.toString().replaceAll("/\\*(.|[\\r\\n])*?\\*/",""); JSONObject json = JSONObject.fromObject(result); PrintWriter out = response.getWriter(); out.print(json.toString()); } catch (IOException e) { e.printStackTrace(); } } }
我是这样实现,希望能帮到其他人。部署后jar包中文件无法直接获取,可用文件流获取。这句话挺重要的
参考:
https://www.douban.com/note/642533897/?qq-pf-to=pcqq.c2c
https://www.cnblogs.com/scofield-yang/p/7883738.html