在 Spring-启动应用中出现错误 "Cause: AMQ119031: Unable to validate user"

Getting an error "Cause: AMQ119031: Unable to validate user" in Spring-Boot app

尝试连接到部署在 JBoss EAP 7.1 上的 ActiveMQ Artemis 队列时出现以下错误。

Error: DefaultMessageListenerContainer: Could not refresh JMS Connection for destination 'jms/queue/QueueA' - retrying using FixedBackOff{interval=5000, currentAttempts=139, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user

这是我使用的代码:

@Bean public DefaultMessageListenerContainer myFactory() throws NamingException { 
   DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer();
   listenerContainer.setConnectionFactory(getConnectionFactory());
   listenerContainer.setDestinationName("jms/queue/QueueA");
   listenerContainer.setMessageListener(new MessageReceiver());
   return listenerContainer; 
}

private ConnectionFactory getConnectionFactory() throws NamingException { 
   final Properties env = new Properties();
   env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory); 
   env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); 
   env.put(Context.SECURITY_PRINCIPAL, "Username"); 
   env.put(Context.SECURITY_CREDENTIALS, "Password"); 
   InitialContext ic = new InitialContext(env); 
   return (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory");
}

如错误消息(即 AMQ119031: Unable to validate user)所示,您在创建 JMS 连接时没有提供正确的凭据。

您在 JNDI 查找的属性中提供的用户名和密码信息适用于 JNDI 查找(即用于 JMS 连接)。 JNDI 和 JMS 100% 相互独立。

您必须使用您的 JMS 用户名和密码配置适当的 Spring 组件,以便它可以在从您的 getConnectionFactory() 方法调用 javax.jms.ConnectionFactory.createConnection(String,String) or javax.jms.ConnectionFactory.createContext(String,String). Try returning an instance of UserCredentialsConnectionFactoryAdapter 时使用。