Spring boot spring引导和freemarker配置TemplateDirectiveModel和TemplateMethodModelEx

Spring boot spring引导和freemarker配置TemplateDirectiveModel和TemplateMethodModelEx,spring-boot,freemarker,Spring Boot,Freemarker,我有一个用SpringBoot+FreeMarker构建的项目,它一直工作到今晚,但我认为我没有改变任何东西;然而,它失败了。下面是我的FreeMarker配置类: @Configuration @Slf4j public class FreemarkerConfiguration extends FreeMarkerAutoConfiguration.FreeMarkerWebConfiguration { /** * autowired all implementatio

我有一个用SpringBoot+FreeMarker构建的项目,它一直工作到今晚,但我认为我没有改变任何东西;然而,它失败了。下面是我的FreeMarker配置类:

@Configuration
@Slf4j
public class FreemarkerConfiguration extends FreeMarkerAutoConfiguration.FreeMarkerWebConfiguration {

    /**
     * autowired all implementations of freemarker.template.TemplateDirectiveModel
     */
    @Autowired
    Map<String, TemplateDirectiveModel> directiveModelMap;
    /**
     * autowired all implementations of freemarker.template.TemplateMethodModelEx
     */
    @Autowired
    Map<String, TemplateMethodModelEx> methodModelExMap;


    private static final String CUSTOM_DIRECTIVE_SUFFIX = "Directive";

    private static final String CUSTOM_METHOD_SUFFIX = "Method";


    @Override
    public FreeMarkerConfigurer freeMarkerConfigurer() {

        FreeMarkerConfigurer configurer = super.freeMarkerConfigurer();

        Map<String, Object> sharedVariables = new HashMap<String, Object>();
        if (!CollectionUtils.isEmpty(directiveModelMap)) {
            Map<String, Object> map = new HashMap<String, Object>();
            for (Map.Entry<String, TemplateDirectiveModel> entry : directiveModelMap.entrySet()) {
                map.put(StringUtils.uncapitalize(entry.getKey()).replaceAll(CUSTOM_DIRECTIVE_SUFFIX, ""), entry.getValue());
            }
            sharedVariables.putAll(map);
        }

        if (!CollectionUtils.isEmpty(this.methodModelExMap)) {
            Map<String, Object> map = new HashMap<String, Object>();
            for (Map.Entry<String, TemplateMethodModelEx> entry : this.methodModelExMap.entrySet()) {
                map.put(StringUtils.uncapitalize(entry.getKey()).replaceAll(CUSTOM_METHOD_SUFFIX, ""), entry.getValue());
            }
            sharedVariables.putAll(map);
        }

        BeansWrapper beansWrapper = new BeansWrapperBuilder(freemarker.template.Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build();
        sharedVariables.put("enums", beansWrapper.getEnumModels());

        configurer.setFreemarkerVariables(sharedVariables);

        return configurer;
    }

}
这是我的
启动应用程序

@Configuration
@SpringBootApplication
@EntityScan("com.hmxx.entity")
@EnableAspectJAutoProxy
@EnableTransactionManagement
@EnableJpaRepositories(value = {"com.hmxx.service"})
public class Application implements CommandLineRunner {

    public static void main(String[] args) {

        SpringApplication app = new SpringApplication(new Object[]{Application.class});

        app.setWebEnvironment(true);
        //app.setBannerMode(Banner.Mode.CONSOLE);
        ConfigurableApplicationContext ctx = app.run(args);
        Map<String, TemplateDirectiveModel> directiveModelMap = ctx.getBeansOfType(TemplateDirectiveModel.class); 
        Map<String, TemplateMethodModelEx> methodModelExMap = ctx.getBeansOfType(TemplateMethodModelEx.class); 
    }

    @Autowired
    DataInitService dataInitService;

    @Override
    public void run(String... args) throws Exception {
//        dataInitService.initAdminUser();
    }
}
@配置
@SpringBoot应用程序
@EntityScan(“com.hmxx.entity”)
@促性腺激素
@启用事务管理
@EnableJParepositions(值={“com.hmxx.service”})
公共类应用程序实现CommandLineRunner{
公共静态void main(字符串[]args){
SpringApplication app=新的SpringApplication(新对象[]{Application.class});
app.setWebEnvironment(true);
//app.setBannerMode(Banner.Mode.CONSOLE);
ConfigurableApplicationContext ctx=app.run(args);
Map-directiveModelMap=ctx.getBeansOfType(TemplateDirectiveModel.class);
MapMethodModelExMap=ctx.getBeansOfType(TemplateMethodModelEx.class);
}
@自动连线
DataInitService DataInitService;
@凌驾
公共无效运行(字符串…参数)引发异常{
//dataInitService.initAdminUser();
}
}
显然,
Map、Map-methodModelExMap
都不是空的


我想知道为什么注入得到
null
,并希望解决它

有趣!相同的代码,不同的计算机有不同的结果;在我工作的电脑上,问题没有出现。真奇怪!到目前为止我还没有找到一个解决办法。很有趣!相同的代码,不同的计算机有不同的结果;在我工作的电脑上,问题没有出现。真奇怪!到目前为止我还没有找到解决办法。
@Override
public FreeMarkerConfigurer freeMarkerConfigurer(){ .... }
@Configuration
@SpringBootApplication
@EntityScan("com.hmxx.entity")
@EnableAspectJAutoProxy
@EnableTransactionManagement
@EnableJpaRepositories(value = {"com.hmxx.service"})
public class Application implements CommandLineRunner {

    public static void main(String[] args) {

        SpringApplication app = new SpringApplication(new Object[]{Application.class});

        app.setWebEnvironment(true);
        //app.setBannerMode(Banner.Mode.CONSOLE);
        ConfigurableApplicationContext ctx = app.run(args);
        Map<String, TemplateDirectiveModel> directiveModelMap = ctx.getBeansOfType(TemplateDirectiveModel.class); 
        Map<String, TemplateMethodModelEx> methodModelExMap = ctx.getBeansOfType(TemplateMethodModelEx.class); 
    }

    @Autowired
    DataInitService dataInitService;

    @Override
    public void run(String... args) throws Exception {
//        dataInitService.initAdminUser();
    }
}