java.lang.ClassNotFoundException: org.apache.velocity.runtime.log.CommonsLogLogChute

报错一

原因是:spring配置里面没有加 velocityConfig

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'velocityConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration$VelocityWebConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.apache.velocity.runtime.resource.loader.ResourceLoader.init(Lorg/apache/velocity/util/ExtProperties;)V

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)

at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)

at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)

at com.hean.iot.eventEngine.EventEngineApplication.main(EventEngineApplication.java:22)

Caused by: java.lang.AbstractMethodError: org.apache.velocity.runtime.resource.loader.ResourceLoader.init(Lorg/apache/velocity/util/ExtProperties;)V

at org.apache.velocity.runtime.resource.ResourceManagerImpl.initialize(ResourceManagerImpl.java:140)

at org.apache.velocity.runtime.RuntimeInstance.initializeResourceManager(RuntimeInstance.java:766)

at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:240)

at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:87)

at org.springframework.ui.velocity.VelocityEngineFactory.createVelocityEngine(VelocityEngineFactory.java:249)

at org.springframework.web.servlet.view.velocity.VelocityConfigurer.afterPropertiesSet(VelocityConfigurer.java:120)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)

... 16 common frames omitted

报错二、 

原因是:pom 里面没有加 velocity 的依赖

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'velocityConfigurer' defined in class path resource [org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration$VelocityWebConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/velocity/runtime/log/CommonsLogLogChute

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)

at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)

at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)

at com.hean.iot.eventEngine.EventEngineApplication.main(EventEngineApplication.java:22)

Caused by: java.lang.NoClassDefFoundError: org/apache/velocity/runtime/log/CommonsLogLogChute

at org.springframework.ui.velocity.VelocityEngineFactory.createVelocityEngine(VelocityEngineFactory.java:238)

at org.springframework.web.servlet.view.velocity.VelocityConfigurer.afterPropertiesSet(VelocityConfigurer.java:120)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)

... 16 common frames omitted

Caused by: java.lang.ClassNotFoundException: org.apache.velocity.runtime.log.CommonsLogLogChute

at java.net.URLClassLoader.findClass(URLClassLoader.java:382)

at java.lang.ClassLoader.loadClass(ClassLoader.java:418)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)

at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

... 20 common frames omitted

综合解决办法

1、 pom 里面加上 velocity 的依赖

<dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>1.6.2</version>
</dependency>

2、spring ApplicationContext.xml 配置里加 velocityConfig 配置

<bean id="velocityConfig"
      class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
    <property name="resourceLoaderPath" value="/WEB-INF/velocity/templates"/>
    <property name="configLocation" value="classpath:config/properties"/>
</bean>

velocity.properties 配置内容

input.encoding=UTF-8
output.encoding=UTF-8

工程配置结构

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cy谭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值