Java – Spring Boot Starter Cache – Velocity is missing

javamavenspring

i am testing Spring Boot 1.3.0.M3 with ehcache and got some problems.

When i'm starting the application following exception occurs on the console:

Exception in thread "main"
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:305)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:667)
at
org.springframework.boot.SpringApplication.doRun(SpringApplication.java:342)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:273)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:971)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:960)
at
com.aconso.creator2.CreatorApplication.main(CreatorApplication.java:26)
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 more Caused by: java.lang.ClassNotFoundException:
org.apache.velocity.runtime.log.CommonsLogLogChute at
java.net.URLClassLoader$1.run(URLClassLoader.java:366) at
java.net.URLClassLoader$1.run(URLClassLoader.java:355) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:354) at
java.lang.ClassLoader.loadClass(ClassLoader.java:425) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at
java.lang.ClassLoader.loadClass(ClassLoader.java:358) … 20 more

My pom.xml:

...
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.0.M3</version>
</parent>
...
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache</artifactId>
    </dependency>
    ...
</dependencies>
...

mvn depency:tree

org.springframework.boot:spring-boot-starter-web:jar:1.3.0.M3:compile
[INFO] | +-
org.springframework.boot:spring-boot-starter:jar:1.3.0.M3:compile
[INFO] | | +-
org.springframework.boot:spring-boot:jar:1.3.0.M3:compile [INFO] | |
+- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.0.M3:compile
[INFO] | | – org.yaml:snakeyaml:jar:1.15:compile [INFO] | +-
org.springframework.boot:spring-boot-starter-validation:jar:1.3.0.M3:compile
[INFO] | | –
org.hibernate:hibernate-validator:jar:5.2.1.Final:compile [INFO] | |
+- javax.validation:validation-api:jar:1.1.0.Final:compile [INFO] | | – com.fasterxml:classmate:jar:1.1.0:compile [INFO] | +-
com.fasterxml.jackson.core:jackson-databind:jar:2.6.1:compile [INFO] |
| +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.1:compile
[INFO] | | –
com.fasterxml.jackson.core:jackson-core:jar:2.6.1:compile [INFO] | +-
org.springframework:spring-web:jar:4.2.0.RELEASE:compile [INFO] | –
org.springframework:spring-webmvc:jar:4.2.0.RELEASE:compile [INFO] |
– org.springframework:spring-expression:jar:4.2.0.RELEASE:compile
[INFO] +-
org.springframework.boot:spring-boot-starter-tomcat:jar:1.3.0.M3:provided
[INFO] | +-
org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.23:provided [INFO] |
+- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.23:compile [INFO] | +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.23:provided
[INFO] | –
org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.23:provided
[INFO] +-
org.springframework.boot:spring-boot-starter-cache:jar:1.3.0.M3:compile
[INFO] | +-
org.springframework:spring-context:jar:4.2.0.RELEASE:compile [INFO] |

org.springframework:spring-context-support:jar:4.2.0.RELEASE:compile
[INFO] +-
org.springframework.boot:spring-boot-starter-security:jar:1.3.0.M3:compile
[INFO] | +- org.springframework:spring-aop:jar:4.2.0.RELEASE:compile
[INFO] | | – aopalliance:aopalliance:jar:1.0:compile [INFO] | +-
org.springframework.security:spring-security-config:jar:4.0.2.RELEASE:compile
[INFO] | –
org.springframework.security:spring-security-web:jar:4.0.2.RELEASE:compile
[INFO] +-
org.springframework.security:spring-security-cas:jar:4.0.2.RELEASE:compile
[INFO] | +- org.jasig.cas.client:cas-client-core:jar:3.3.3:compile
[INFO] | | – org.opensaml:opensaml:jar:2.5.1-1:compile [INFO] | |
+- org.opensaml:openws:jar:1.4.2-1:compile [INFO] | | | +- org.opensaml:xmltooling:jar:1.3.2-1:compile [INFO] | | | | +-
org.slf4j:log4j-over-slf4j:jar:1.7.12:compile [INFO] | | | | +-
joda-time:joda-time:jar:2.8.1:compile [INFO] | | | | +-
org.bouncycastle:bcprov-jdk15:jar:1.45:compile [INFO] | | | |
+- org.apache.santuario:xmlsec:jar:1.4.4:compile [INFO] | | | | +- ca.juliusdavies:not-yet-commons-ssl:jar:0.3.9:compile [INFO] | | | | – net.jcip:jcip-annotations:jar:1.0:compile [INFO] | | |
+- commons-codec:commons-codec:jar:1.3:compile [INFO] | | | – commons-httpclient:commons-httpclient:jar:3.1:compile [INFO] | |
+- commons-collections:commons-collections:jar:3.2.1:compile [INFO] | | +- commons-lang:commons-lang:jar:2.1:compile [INFO] | | +-
velocity:velocity:jar:1.5:compile [INFO] | | +-
org.owasp.esapi:esapi:jar:2.0GA:compile [INFO] | | +-
xml-apis:xml-apis:jar:1.4.01:compile [INFO] | | +-
xerces:xercesImpl:jar:2.10.0:runtime [INFO] | | +-
xml-resolver:xml-resolver:jar:1.2:runtime [INFO] | | –
xalan:xalan:jar:2.7.1:runtime [INFO] | | –
xalan:serializer:jar:2.7.1:runtime [INFO] | +-
org.springframework.security:spring-security-core:jar:4.0.2.RELEASE:compile
[INFO] | +-
org.springframework:spring-beans:jar:4.2.0.RELEASE:compile [INFO] |
– org.springframework:spring-core:jar:4.2.0.RELEASE:compile [INFO] +-
org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.3.0.M3:compile
[INFO] | +- org.thymeleaf:thymeleaf-spring4:jar:2.1.4.RELEASE:compile
[INFO] | –
nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.2.9:compile
[INFO] +-
org.thymeleaf.extras:thymeleaf-extras-springsecurity4:jar:2.1.2.RELEASE:compile
[INFO] | +- org.thymeleaf:thymeleaf:jar:2.1.4.RELEASE:compile [INFO]
| | +- ognl:ognl:jar:3.0.8:compile [INFO] | | +-
org.javassist:javassist:jar:3.18.1-GA:compile [INFO] | | –
org.unbescape:unbescape:jar:1.1.0.RELEASE:compile [INFO] | –
org.slf4j:slf4j-api:jar:1.7.12:compile [INFO] +-
org.springframework.boot:spring-boot-starter-log4j2:jar:1.3.0.M3:compile
[INFO] | +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.3:compile
[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.3:compile [INFO]
| +- org.apache.logging.log4j:log4j-core:jar:2.3:compile [INFO] | +-
org.slf4j:jcl-over-slf4j:jar:1.7.12:compile [INFO] | –
org.slf4j:jul-to-slf4j:jar:1.7.12:compile [INFO] +-
org.springframework.boot:spring-boot-starter-actuator:jar:1.3.0.M3:compile
[INFO] | –
org.springframework.boot:spring-boot-actuator:jar:1.3.0.M3:compile
[INFO] +-
org.springframework.boot:spring-boot-starter-data-jpa:jar:1.3.0.M3:compile
[INFO] | +-
org.springframework.boot:spring-boot-starter-aop:jar:1.3.0.M3:compile
[INFO] | | +- org.aspectj:aspectjrt:jar:1.8.6:compile [INFO] | |
– org.aspectj:aspectjweaver:jar:1.8.6:compile [INFO] | +-
org.springframework.boot:spring-boot-starter-jdbc:jar:1.3.0.M3:compile
[INFO] | | +- org.apache.tomcat:tomcat-jdbc:jar:8.0.23:compile
[INFO] | | | – org.apache.tomcat:tomcat-juli:jar:8.0.23:compile
[INFO] | | –
org.springframework:spring-jdbc:jar:4.2.0.RELEASE:compile [INFO] | +-
org.hibernate:hibernate-entitymanager:jar:4.3.10.Final:compile [INFO]
| | +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile [INFO] |
| +-
org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] | | +- org.hibernate:hibernate-core:jar:4.3.10.Final:compile
[INFO] | | | +- antlr:antlr:jar:2.7.7:compile [INFO] | | | –
org.jboss:jandex:jar:1.1.0.Final:compile [INFO] | | +-
dom4j:dom4j:jar:1.6.1:compile [INFO] | | +-
org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] | | –
org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] | +-
org.springframework.data:spring-data-jpa:jar:1.9.0.RC1:compile [INFO]
| | +-
org.springframework.data:spring-data-commons:jar:1.11.0.RC1:compile
[INFO] | | +-
org.springframework:spring-orm:jar:4.2.0.RELEASE:compile [INFO] | |
– org.springframework:spring-tx:jar:4.2.0.RELEASE:compile [INFO] |
– org.springframework:spring-aspects:jar:4.2.0.RELEASE:compile [INFO]
+- org.hsqldb:hsqldb:jar:2.3.3:runtime [INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.3.0.M3:test
[INFO] | +- junit:junit:jar:4.12:test [INFO] | +-
org.mockito:mockito-core:jar:1.10.19:test [INFO] | | –
org.objenesis:objenesis:jar:2.1:test [INFO] | +-
org.hamcrest:hamcrest-core:jar:1.3:test [INFO] | +-
org.hamcrest:hamcrest-library:jar:1.3:test [INFO] | –
org.springframework:spring-test:jar:4.2.0.RELEASE:test [INFO] +-
org.webjars:angularjs:jar:1.4.2:compile [INFO] +-
org.webjars:jquery:jar:2.1.4:compile [INFO] +-
org.webjars:bootstrap:jar:3.3.5:compile [INFO] +-
org.webjars:angular-file-upload:jar:5.0.0:compile [INFO] +-
net.sf.jtidy:jtidy:jar:r938:compile [INFO] +-
org.jsoup:jsoup:jar:1.8.2:compile [INFO] –
net.sf.ehcache:ehcache:jar:2.10.0:compile

I have an ehcache.xml in my classpath and the EHCacheManager is instantiated.
When i remove the spring-boot-starter-cache- and ehcache-dependency everything starts fine. (But then only with ConcurrentMapCacheManager)

Question:

Do I need velocity with spring-boot-starter-cache or is there something other missing or wrong?

Best Answer

I had the same issue with spring-security-cas depending on velocity. You can solve the problem by adding

@EnableAutoConfiguration(exclude = VelocityAutoConfiguration.class)

to your spring boot application main class