看公司代码时的一些记录

freemarker中加载不了其他文件,服务器显示404.
这里写图片描述

1.ApplicationListener 监听器

2.容器加载完毕做一件事(利用ContextRefreshedEvent事件):很多时候我们想要在某个类加载完毕时干某件事情,但是使用了spring管理对象,我们这个类引用了其他类(可能是更复杂的关联),所以当我们去使用这个类做事情时发现报空指针错误,这是因为我们这个类有可能已经初始化完成,但是引用的其他类不一定初始化完成,所以发生了空指针错误

3.WebMvcConfigurerAdapter

4.freemarker.template.Configuration.setSharedVariable()

官方api是这样说的
SharedVariables are variables that are defined for all templates..
You can add shared variables to the configuration with the setSharedVariable methods:

Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
...
cfg.setSharedVariable("warp", new WarpDirective());
cfg.setSharedVariable("company", "Foo Inc.");

问题解决:application.yml中的classic_compatible和auto_import缺一不可

freemarker:
    content-type: text/html
    suffix: .html
    settings:
      classic_compatible: true
      auto_import: /ftl/pony/index.ftl as p,/ftl/spring.ftl as s,/pages/global/ztitle.html as z

下面这句话的意思是页面文件中引入的外部文件都放在/mag/res文件夹中

        cfg.setSharedVariable("res", propMy.getResbase());
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章