我在Springboot项目中使用RabbitMQ:
sender
@Component
@AllArgsConstructor
public class UserSender {
private final RabbitTemplate rabbitTemplate;
public String send() {
User user = new User(1L, "Tom", "123");
rabbitTemplate.convertAndSend("userQueue", user);
return "user sender sent: " + user;
}
}
Receiver
@Component
public class UserReceiver {
@RabbitListener(queues = "userQueue")
@RabbitHandler
private void process(User user) {
System.out.println("received user: " + user);
}
}
启动时出现异常:
Caused by: java.lang.SecurityException: Attempt to deserialize unauthorized class com.example.lab06.entity.User; add allowed class name patterns to the message converter or, if you trust the message orginiator, set environment variable 'SPRING_AMQP_DESERIALIZATION_TRUST_ALL' or system property 'spring.amqp.deserialization.trust.all' to true
我检查了Spring AMPQ 文档
You can set the patterns using the allowedListPatterns property on these converters. Alternatively, if you trust all message originators, you can set the environment variable SPRING_AMQP_DESERIALIZATION_TRUST_ALL or system property spring.amqp.deserialization.trust.all to true.
但我无法将
spring.amqp.deserialization.trust.all
中的application.properties
设置为Cannot resolve configuration property 'spring.amqp.deserialization.trust.all'
如何解决?
谢谢!
文档指出(强调我的):
...将 环境变量
或 系统属性SPRING_AMQP_DESERIALIZATION_TRUST_ALL
设置为spring.amqp.deserialization.trust.all
。true
application.properties
中配置的值不是环境变量或系统属性。环境变量在您的环境中设置,系统属性通常作为 -D
参数传递到 JVM。