Spring Boot Starter Cache - 缺少速度?
Posted
技术标签:
【中文标题】Spring Boot Starter Cache - 缺少速度?【英文标题】:Spring Boot Starter Cache - Velocity is missing? 【发布时间】:2015-11-11 02:46:19 【问题描述】:我正在使用 ehcache 测试 Spring Boot 1.3.0.M3 并遇到了一些问题。
当我启动应用程序时,控制台上出现以下异常:
线程“main”中的异常 org.springframework.beans.factory.BeanCreationException:错误 创建在类路径中定义的名称为“velocityConfigurer”的bean 资源 [org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration$VelocityWebConfiguration.class]: 调用 init 方法失败;嵌套异常是 java.lang.NoClassDefFoundError: org/apache/velocity/runtime/log/CommonsLogLogChute 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 在 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:667) 在 org.springframework.boot.SpringApplication.doRun(SpringApplication.java:342) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:273) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:971) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:960) 在 com.aconso.creator2.CreatorApplication.main(CreatorApplication.java:26) 引起:java.lang.NoClassDefFoundError: org/apache/velocity/runtime/log/CommonsLogLogChute 在 org.springframework.ui.velocity.VelocityEngineFactory.createVelocityEngine(VelocityEngineFactory.java:238) 在 org.springframework.web.servlet.view.velocity.VelocityConfigurer.afterPropertiesSet(VelocityConfigurer.java:120) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ... 16 更多原因:java.lang.ClassNotFoundException: org.apache.velocity.runtime.log.CommonsLogLogChute 在 java.net.URLClassLoader$1.run(URLClassLoader.java:366) 在 java.net.URLClassLoader$1.run(URLClassLoader.java:355) 在 java.security.AccessController.doPrivileged(Native Method) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:354) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:425) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 20 更多
我的 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 依赖:树
org.springframework.boot:spring-boot-starter-web:jar:1.3.0.M3:compile [信息] | +- org.springframework.boot:spring-boot-starter:jar:1.3.0.M3:compile [信息] | | +- org.springframework.boot:spring-boot:jar:1.3.0.M3:compile [INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.0.M3:compile [信息] | | - org.yaml:snakeyaml:jar:1.15:compile [INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:1.3.0.M3:compile [信息] | | - 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 [信息] | | - 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 [信息] +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.3.0.M3:provided [信息] | +- 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 [信息] | - org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.23:provided [信息] +- org.springframework.boot:spring-boot-starter-cache:jar:1.3.0.M3:compile [信息] | +- org.springframework:spring-context:jar:4.2.0.RELEASE:compile [INFO] | - org.springframework:spring-context-support:jar:4.2.0.RELEASE:compile [信息] +- org.springframework.boot:spring-boot-starter-security:jar:1.3.0.M3:compile [信息] | +- org.springframework:spring-aop:jar:4.2.0.RELEASE:compile [信息] | | - aopalliance:aopalliance:jar:1.0:compile [INFO] | +- org.springframework.security:spring-security-config:jar:4.0.2.RELEASE:compile [信息] | - org.springframework.security:spring-security-web:jar:4.0.2.RELEASE:compile [信息] +- org.springframework.security:spring-security-cas:jar:4.0.2.RELEASE:compile [信息] | +- org.jasig.cas.client:cas-client-core:jar:3.3.3:compile [信息] | | - 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] | | +- 速度:速度:罐子:1.5:编译 [信息] | | +- 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 [信息] | | +- xml-resolver:xml-resolver:jar:1.2:runtime [INFO] | | - xalan:xalan:jar:2.7.1:runtime [信息] | | - xalan:serializer:jar:2.7.1:runtime [信息] | +- org.springframework.security:spring-security-core:jar:4.0.2.RELEASE:compile [信息] | +- 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 [信息] | +- org.thymeleaf:thymeleaf-spring4:jar:2.1.4.RELEASE:compile [信息] | - nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.2.9:compile [信息] +- org.thymeleaf.extras:thymeleaf-extras-springsecurity4:jar:2.1.2.RELEASE:compile [信息] | +- 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:编译 [信息] | | - 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 [信息] | +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.3:compile [信息] | +- org.apache.logging.log4j:log4j-api:jar:2.3:compile [信息] | +- 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 [信息] | - org.springframework.boot:spring-boot-actuator:jar:1.3.0.M3:compile [信息] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.3.0.M3:compile [信息] | +- org.springframework.boot:spring-boot-starter-aop:jar:1.3.0.M3:compile [信息] | | +- 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 [信息] | | +- org.apache.tomcat:tomcat-jdbc:jar:8.0.23:compile [信息] | | | - org.apache.tomcat:tomcat-juli:jar:8.0.23:compile [信息] | | - 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 [信息] | | +- org.hibernate:hibernate-core:jar:4.3.10.Final:compile [信息] | | | +- antlr:antlr:jar:2.7.7:compile [INFO] | | | - org.jboss:jandex:jar:1.1.0.Final:compile [INFO] | | +- dom4j:dom4j:jar:1.6.1:编译 [信息] | | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile [信息] | | - org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile [信息] | +- javax.transaction:javax.transaction-api:jar:1.2:compile [信息] | +- 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 [信息] | | +- 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 [信息] | +- junit:junit:jar:4.12:test [INFO] | +- org.mockito:mockito-core:jar:1.10.19:test [信息] | | - org.objenesis:objenesis:jar:2.1:test [INFO] | +- org.hamcrest:hamcrest-core:jar:1.3:test [信息] | +- 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:编译
我的类路径中有一个 ehcache.xml,并且实例化了 EHCacheManager。 当我删除 spring-boot-starter-cache- 和 ehcache-dependency 时,一切都开始正常。 (但只能使用 ConcurrentMapCacheManager)
问题:
我是否需要 spring-boot-starter-cache 的速度或是否有其他缺失或错误?
【问题讨论】:
看来 CommonsLogLogChute 不在你的 classPath 中。 :"嵌套异常是 java.lang.NoClassDefFoundError: org/apache/velocity/runtime/log/CommonsLogLogChute" 【参考方案1】:我对 spring-security-cas 有同样的问题,具体取决于速度。您可以通过添加来解决问题
@EnableAutoConfiguration(exclude = VelocityAutoConfiguration.class)
到你的 Spring Boot 应用程序主类
【讨论】:
【参考方案2】:VelocityAutoConfiguration
仅在类路径中存在这两个类时才会生效:
@ConditionalOnClass( VelocityEngine.class, VelocityEngineFactory.class )
它们分别来自org.apache.velocity:velocity
和org.springframework:spring-context-support
。
您可以通过以下方式确定哪些依赖项将这些依赖项传递到项目中:
mvn dependency:tree
【讨论】:
使用 spring-starter-cache 和 ehcache 需要速度吗?当需要它时,为什么 spring-data-cache 没有它作为依赖项?我使用 thymeleaf 作为模板引擎,也不需要速度。 好的,org.springframework:spring-context-support 在我的依赖项中。它来自 org.springframework.boot:spring-boot-starter-cache。但我在我的依赖树中没有找到 org.apache.velocity:velocity。 也许名字稍有不同,试试mvn dependency:tree | grep velocity
嗯,好的。我编辑了我的帖子并添加了依赖项:树。似乎 spring-security-cas 依赖于velocity:velocity:jar。我现在的解决方案是添加 spring-boot-starter-velocity 依赖项并通过 spring.velocity.enabled=false 在 application.properties 中禁用它。之后它似乎工作正常。【参考方案3】:
使用最新版本的 Spring Boot,你可以做到这一点 -
@SpringBootApplication(exclude = VelocityAutoConfiguration.class)
【讨论】:
以上是关于Spring Boot Starter Cache - 缺少速度?的主要内容,如果未能解决你的问题,请参考以下文章