SpringBoot报错: Error creating bean with name freeMarkerConfigurer defined in class path resource

I didn’t look at the almanac when I wrote the code today. I added some code. The project cannot run. The project error is as follows:

2020-05-25 10:00:03.913 - [ERROR] - [org.springframework.boot.SpringApplication:reportFailure:858] - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'freeMarkerConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/freemarker/FreeMarkerServletWebConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
        at com.yueniu.yngp.YngpServer.main(YngpServer.java:34)
        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.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ExceptionInInitializerError: null
        at org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.newConfiguration(FreeMarkerConfigurationFactory.java:327)
        at org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.createConfiguration(FreeMarkerConfigurationFactory.java:257)
                                                                     

Du Niang found that they all said that the jar package version was too low and needed to upgrade the freemaker version. But I am already a higher version. It seems that the problem is not here. Then use Google search and found:
Insert picture description here
There are two solutions:

1: In the configuration file, set: spring.freemarker.check-template-location=false

But I don't use freemaker for page processing. So this solution passed.

2: Filter to the freemakerConfiguration class in the automatic annotation.

Specific solution: add to your spring boot startup class:

@EnableAutoConfiguration(exclude = {
    
     FreeMarkerAutoConfiguration.class })

That's it. This is filtered out.

Restart the startup project and access it normally.

to sum up:

This problem is mainly caused by the @EnableAutoConfiguration annotation of spring boot.

This is my WeChat official account: Program Yuanwei Magazine For more articles, please follow WeChat official account
Insert picture description here

Guess you like

Origin blog.csdn.net/CharlesYooSky/article/details/106327868
Recommended