org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration 上的错误处理条件
Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
将如下所示的 2 个依赖项添加到我的应用程序后,一切正常,我的会话数据已写入我的本地 redis 服务器,但是当我尝试指定 redis 服务器的不同地址时,出现错误。我假设错误与某些依赖项问题有关,但我不知道如何解决这个问题。
compile "org.springframework.boot:spring-boot-starter-data-redis-reactive:${springVersion}"
compile "org.springframework.session:spring-session-data-redis:${springVersion}"
启动时出错
java.lang.IllegalStateException: Error processing condition on
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
at
org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:180)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:328)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:61)
~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
pl.bk.pizza.store.Initializer.main(Initializer.java:11) [classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect Class
[org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration]
from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at
org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:569)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:541)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:599)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:724)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:665)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:633)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1012)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:164)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanType(BeanTypeRegistry.java:153)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.updateTypesIfNecessary(BeanTypeRegistry.java:203)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.getNamesForType(BeanTypeRegistry.java:115)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:265)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:254)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:196)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:116)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] ... 17
common frames omitted Caused by: java.lang.NoClassDefFoundError:
javax/servlet/Filter at java.lang.ClassLoader.defineClass1(Native
Method) ~[na:1.8.0-internal] at
java.lang.ClassLoader.defineClass(ClassLoader.java:763)
~[na:1.8.0-internal] at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
~[na:1.8.0-internal] at
java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
~[na:1.8.0-internal] at
java.net.URLClassLoader.access0(URLClassLoader.java:73)
~[na:1.8.0-internal] at
java.net.URLClassLoader.run(URLClassLoader.java:368)
~[na:1.8.0-internal] at
java.net.URLClassLoader.run(URLClassLoader.java:362)
~[na:1.8.0-internal] at
java.security.AccessController.doPrivileged(Native Method)
~[na:1.8.0-internal] at
java.net.URLClassLoader.findClass(URLClassLoader.java:361)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:424)
~[na:1.8.0-internal] at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
~[na:1.8.0-internal] at java.lang.ClassLoader.defineClass1(Native
Method) ~[na:1.8.0-internal] at
java.lang.ClassLoader.defineClass(ClassLoader.java:763)
~[na:1.8.0-internal] at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
~[na:1.8.0-internal] at
java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
~[na:1.8.0-internal] at
java.net.URLClassLoader.access0(URLClassLoader.java:73)
~[na:1.8.0-internal] at
java.net.URLClassLoader.run(URLClassLoader.java:368)
~[na:1.8.0-internal] at
java.net.URLClassLoader.run(URLClassLoader.java:362)
~[na:1.8.0-internal] at
java.security.AccessController.doPrivileged(Native Method)
~[na:1.8.0-internal] at
java.net.URLClassLoader.findClass(URLClassLoader.java:361)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:424)
~[na:1.8.0-internal] at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
~[na:1.8.0-internal] at java.lang.Class.getDeclaredMethods0(Native
Method) ~[na:1.8.0-internal] at
java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
~[na:1.8.0-internal] at
java.lang.Class.getDeclaredMethods(Class.java:1975)
~[na:1.8.0-internal] at
org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] ... 35 common frames
omitted Caused by: java.lang.ClassNotFoundException:
javax.servlet.Filter at
java.net.URLClassLoader.findClass(URLClassLoader.java:381)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:424)
~[na:1.8.0-internal] at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
~[na:1.8.0-internal] ... 63 common frames omitted
Redis配置
@Configuration
@EnableRedisHttpSession
public class RedisConfig
{
@Bean
LettuceConnectionFactory jedisConnectionFactory()
{
final RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName("redis-19999.c14.us-east-1-2.ec2.cloud.redislabs.com");
config.setPort(19999);
config.setPassword(RedisPassword.of("***"));
return new LettuceConnectionFactory();
}
}
build.gradle 文件
buildscript {
ext.springVersion = '2.0.2.RELEASE'
ext.gradleDocker = '1.2'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "se.transmode.gradle:gradle-docker:$gradleDocker"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springVersion"
}
}
plugins {
id "org.sonarqube" version "2.6.2"
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'
apply plugin: 'docker'
apply plugin: 'jacoco'
dependencies {
// spring
compile "org.springframework.boot:spring-boot-starter-webflux:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-data-mongodb-reactive:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-security:${springVersion}"
testCompile "org.springframework.security:spring-security-test:${springSecurityTest}"
testCompile "org.springframework.boot:spring-boot-starter-test:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-data-redis-reactive:${springVersion}"
compile "org.springframework.session:spring-session-data-redis:${springVersion}"
// utils
testCompile "org.assertj:assertj-core:${assertJ}"
compile "com.google.guava:guava:${guava}"
compile "io.projectreactor:reactor-core:${reactor}"
compile "io.reactivex.rxjava2:rxjava:${rxjava}"
compile "commons-lang:commons-lang:${commonsLang}"
compile "commons-validator:commons-validator:${commonsLangValidator}"
compileOnly "org.projectlombok:lombok:${lombok}"
// embedded mongo for tests
testCompile "de.flapdoodle.embed:de.flapdoodle.embed.mongo:${embeddedMongo}"
// spock
compile "org.codehaus.groovy:groovy-all:${groovy}"
testCompile "org.spockframework:spock-core:${spockCore}"
testCompile "org.spockframework:spock-spring:${spockSpring}"
}
这里发生了几件事。
您提供的日志表明类路径中缺少 javax.servlet.Filter
,而您的构建脚本和依赖项建议您构建 Spring WebFlux 应用程序。我怀疑这是由于您使用 @EnableRedisHttpSession
(注意那里的 HttpSession
?)而不是 @EnableRedisWebSession
显式配置 Spring Session 的 Servlet 支持。更好的是,您应该将 Spring 会话配置留给 Spring 引导以自动配置它 - 请参阅 Spring 引导参考手册的 Spring Session dedicated section。
相同的建议(避免显式配置,依赖自动配置)适用于您的 Redis 配置,即不需要显式 LettuceConnectionFactory
bean。
此外,对于 Spring Boot,强烈建议使用其依赖管理,而不是显式提供依赖的版本,至少对于 Spring Boot 的依赖所涵盖的依赖管理。参考dependency management and dependency versions appendix sections of Boot's reference manual. On top of that, you should also strongly consider using Boot's starters to make sure all the required dependencies are pulled in - see starters dedicated section.
如果您通过 spring initializr 创建应用程序,将 Session 指定为依赖项,创建 @RestController
然后使用 @EnableSpringHttpSession
,则会出现相同的错误消息。
不使用 @EnableSpringHttpSession
,应用程序将启动和退出,没有堆栈跟踪。这给人的感觉可能是 HttpSession 配置有问题。
错误情况的实际原因是没有将 Web
作为应用程序依赖项(或 build.gradle 中的 implementation('org.springframework.boot:spring-boot-starter-web'
)
对我来说,一切都很完美,但它仍然抛出异常-Propertyplaceholderautoconfiguration
我刚刚尝试了 maven 重新加载和项目重新加载,但它仍然抛出此错误并显示一些关于依赖项的红线 Class 这是我用来导入并在我的项目文件中使用它的
刚刚关闭了IntelliJ,再次打开项目,然后一切正常。
对你有用的话点赞
将如下所示的 2 个依赖项添加到我的应用程序后,一切正常,我的会话数据已写入我的本地 redis 服务器,但是当我尝试指定 redis 服务器的不同地址时,出现错误。我假设错误与某些依赖项问题有关,但我不知道如何解决这个问题。
compile "org.springframework.boot:spring-boot-starter-data-redis-reactive:${springVersion}"
compile "org.springframework.session:spring-session-data-redis:${springVersion}"
启动时出错
java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:180) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:328) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:61) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at pl.bk.pizza.store.Initializer.main(Initializer.java:11) [classes/:na] Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:569) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:541) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:599) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:724) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:665) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:633) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1012) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:164) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanType(BeanTypeRegistry.java:153) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.updateTypesIfNecessary(BeanTypeRegistry.java:203) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.getNamesForType(BeanTypeRegistry.java:115) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:265) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:254) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:196) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:116) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] ... 17 common frames omitted Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0-internal] at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[na:1.8.0-internal] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0-internal] at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) ~[na:1.8.0-internal] at java.net.URLClassLoader.access0(URLClassLoader.java:73) ~[na:1.8.0-internal] at java.net.URLClassLoader.run(URLClassLoader.java:368) ~[na:1.8.0-internal] at java.net.URLClassLoader.run(URLClassLoader.java:362) ~[na:1.8.0-internal] at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0-internal] at java.net.URLClassLoader.findClass(URLClassLoader.java:361) ~[na:1.8.0-internal] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0-internal] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0-internal] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0-internal] at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0-internal] at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[na:1.8.0-internal] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0-internal] at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) ~[na:1.8.0-internal] at java.net.URLClassLoader.access0(URLClassLoader.java:73) ~[na:1.8.0-internal] at java.net.URLClassLoader.run(URLClassLoader.java:368) ~[na:1.8.0-internal] at java.net.URLClassLoader.run(URLClassLoader.java:362) ~[na:1.8.0-internal] at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0-internal] at java.net.URLClassLoader.findClass(URLClassLoader.java:361) ~[na:1.8.0-internal] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0-internal] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0-internal] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0-internal] at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0-internal] at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0-internal] at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0-internal] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] ... 35 common frames omitted Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0-internal] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0-internal] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0-internal] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0-internal] ... 63 common frames omitted
Redis配置
@Configuration
@EnableRedisHttpSession
public class RedisConfig
{
@Bean
LettuceConnectionFactory jedisConnectionFactory()
{
final RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName("redis-19999.c14.us-east-1-2.ec2.cloud.redislabs.com");
config.setPort(19999);
config.setPassword(RedisPassword.of("***"));
return new LettuceConnectionFactory();
}
}
build.gradle 文件
buildscript {
ext.springVersion = '2.0.2.RELEASE'
ext.gradleDocker = '1.2'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "se.transmode.gradle:gradle-docker:$gradleDocker"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springVersion"
}
}
plugins {
id "org.sonarqube" version "2.6.2"
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'
apply plugin: 'docker'
apply plugin: 'jacoco'
dependencies {
// spring
compile "org.springframework.boot:spring-boot-starter-webflux:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-data-mongodb-reactive:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-security:${springVersion}"
testCompile "org.springframework.security:spring-security-test:${springSecurityTest}"
testCompile "org.springframework.boot:spring-boot-starter-test:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-data-redis-reactive:${springVersion}"
compile "org.springframework.session:spring-session-data-redis:${springVersion}"
// utils
testCompile "org.assertj:assertj-core:${assertJ}"
compile "com.google.guava:guava:${guava}"
compile "io.projectreactor:reactor-core:${reactor}"
compile "io.reactivex.rxjava2:rxjava:${rxjava}"
compile "commons-lang:commons-lang:${commonsLang}"
compile "commons-validator:commons-validator:${commonsLangValidator}"
compileOnly "org.projectlombok:lombok:${lombok}"
// embedded mongo for tests
testCompile "de.flapdoodle.embed:de.flapdoodle.embed.mongo:${embeddedMongo}"
// spock
compile "org.codehaus.groovy:groovy-all:${groovy}"
testCompile "org.spockframework:spock-core:${spockCore}"
testCompile "org.spockframework:spock-spring:${spockSpring}"
}
这里发生了几件事。
您提供的日志表明类路径中缺少 javax.servlet.Filter
,而您的构建脚本和依赖项建议您构建 Spring WebFlux 应用程序。我怀疑这是由于您使用 @EnableRedisHttpSession
(注意那里的 HttpSession
?)而不是 @EnableRedisWebSession
显式配置 Spring Session 的 Servlet 支持。更好的是,您应该将 Spring 会话配置留给 Spring 引导以自动配置它 - 请参阅 Spring 引导参考手册的 Spring Session dedicated section。
相同的建议(避免显式配置,依赖自动配置)适用于您的 Redis 配置,即不需要显式 LettuceConnectionFactory
bean。
此外,对于 Spring Boot,强烈建议使用其依赖管理,而不是显式提供依赖的版本,至少对于 Spring Boot 的依赖所涵盖的依赖管理。参考dependency management and dependency versions appendix sections of Boot's reference manual. On top of that, you should also strongly consider using Boot's starters to make sure all the required dependencies are pulled in - see starters dedicated section.
如果您通过 spring initializr 创建应用程序,将 Session 指定为依赖项,创建 @RestController
然后使用 @EnableSpringHttpSession
,则会出现相同的错误消息。
不使用 @EnableSpringHttpSession
,应用程序将启动和退出,没有堆栈跟踪。这给人的感觉可能是 HttpSession 配置有问题。
错误情况的实际原因是没有将 Web
作为应用程序依赖项(或 build.gradle 中的 implementation('org.springframework.boot:spring-boot-starter-web'
)
对我来说,一切都很完美,但它仍然抛出异常-Propertyplaceholderautoconfiguration
我刚刚尝试了 maven 重新加载和项目重新加载,但它仍然抛出此错误并显示一些关于依赖项的红线 Class 这是我用来导入并在我的项目文件中使用它的
刚刚关闭了IntelliJ,再次打开项目,然后一切正常。 对你有用的话点赞