我刚刚将我的 Spring Boot 应用程序从 Java 11 升级到 17。我正在使用 Spring 集成XstreamMarshaller
并将MessageConverter
ActiveMQ Artemis 消息(XML 格式)转换为 Java 对象,但XstreamMarshaller
该类似乎无法与 openjdk 17 一起正常工作。这是例外:
org.springframework.jms.support.converter.MessageConversionException: Could not unmarshal message: ActiveMQMessage[ID:d0af36a0-32ac-11ec-b7ed-9cda3e9bf249]:PERSISTENT/ClientMessageImpl[messageID=1443, durable=true, address=batch_table,userID=d0af36a0-32ac-11ec-b7ed-9cda3e9bf249,properties=TypedProperties[__AMQ_CID=cd8a28dd-32ac-11ec-b7ed-9cda3e9bf249,_AMQ_ROUTING_TYPE=1]]; nested exception is
org.springframework.oxm.UnmarshallingFailureException: XStream unmarshalling exception; nested exception is com.thoughtworks.xstream.security.ForbiddenClassException
这是侦听器 bean 配置:
@Bean
public SimpleMessageListenerContainer messageListenerContainer() {
SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer();
simpleMessageListenerContainer.setConnectionFactory(connectionFactory);
simpleMessageListenerContainer.setDestinationName(queue);
simpleMessageListenerContainer.getMessageListener();
simpleMessageListenerContainer.setConnectLazily(false);
simpleMessageListenerContainer.setAutoStartup(true);
simpleMessageListenerContainer.setSessionTransacted(true);
return simpleMessageListenerContainer;
}
@Bean
public JmsMessageDrivenEndpoint jmsMessageDrivenEndpoint() {
ChannelPublishingJmsMessageListener channelPublishingJmsMessageListener = new ChannelPublishingJmsMessageListener();
channelPublishingJmsMessageListener.setRequestChannel(inputChannel());
channelPublishingJmsMessageListener.setMessageConverter(messageConverter());
return new JmsMessageDrivenEndpoint(messageListenerContainer(),
channelPublishingJmsMessageListener);
}
@Bean
MessageConverter messageConverter() {
XStreamMarshaller marshaller = new XStreamMarshaller();
Map<String, Class<?>> aliases = new HashMap<>();
aliases.put("Table", TableMessage.class);
marshaller.setAliases(aliases);
MarshallingMessageConverter messageConverter = new MarshallingMessageConverter(marshaller);
messageConverter.setTargetType(MessageType.MAP);
return messageConverter;
}
版本:
- 弹簧启动:2.5.6
- Xstream:1.4.18
- 春牛:5.3.12