我构建了一个Web应用程序,通过Redisson驱动程序与Redis缓存集群通信。 Redisson驱动程序从YAML文件加载其配置。 该配置包含使用用于创建对象的构造函数创建的一些属性。 由于某些原因,由于这些构造函数方法调用而导致配置无法加载,并出现以下错误:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SessionManagement]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:939)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1812)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: Can't construct a java object for org.redisson.connection.balancer.RoundRobinLoadBalancer; exception=Invalid tag: org.redisson.connection.balancer.RoundRobinLoadBalancer
in 'reader', line 14, column 17:
loadBalancer: !<org.redisson.connection.balanc ...
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:350)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:373)
这是YAML文件:
---
clusterServersConfig:
idleConnectionTimeout: 10000
pingTimeout: 1000
connectTimeout: 1000
timeout: 1000
retryAttempts: 3
retryInterval: 1000
reconnectionTimeout: 3000
failedAttempts: 3
password: null
subscriptionsPerConnection: 5
clientName: null
loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {}
slaveSubscriptionConnectionMinimumIdleSize: 1
slaveSubscriptionConnectionPoolSize: 25
slaveConnectionMinimumIdleSize: 5
slaveConnectionPoolSize: 100
masterConnectionMinimumIdleSize: 5
masterConnectionPoolSize: 100
readMode: "SLAVE"
nodeAddresses:
- "//172.31.150.113:7000"
- "//172.31.150.113:7001"
- "//172.31.150.113:7002"
- "//172.31.150.113:7003"
- "//172.31.150.113:7004"
- "//172.31.150.113:7005"
scanInterval: 1000
threads: 0
codec: !<org.redisson.codec.JsonJacksonCodec> {}
useLinuxNativeEpoll: false
eventLoopGroup: null
我验证了对象创建所需的redisson库在类路径上 有没有人知道为什么Snakeyaml无法正确加载这个YAML文件?
答案 0 :(得分:2)
当使用该表单加载为没有预定义标记的javabean时,我相信语法是两个感叹号,没有周围的标记。即。
codec: !!org.redisson.codec.JsonJacksonCodec{}
如果使用构造函数和预定义标记加载为类,则使用括号代替大括号:
codec: !org.redisson.codec.JsonJacksonCodec[]
如果这没有帮助,请考虑发布您正在使用的Snakeyaml版本。