# 37.5 混合XA和non-XA的JMS连接

当使用JTA时，primary JMS `ConnectionFactory`bean将能识别XA，并参与到分布式事务中。有些情况下，你可能需要使用non-XA的`ConnectionFactory`去处理一些JMS消息。例如，你的JMS处理逻辑可能比XA超时时间长。

如果想使用一个non-XA的`ConnectionFactory`，你可以注入`nonXaJmsConnectionFactory` bean而不是`@Primary` `jmsConnectionFactory` bean。为了保持一致，`jmsConnectionFactory` bean将以别名`xaJmsConnectionFactor`来被使用。

示例如下：

```java
// Inject the primary (XA aware) ConnectionFactory
@Autowired
private ConnectionFactory defaultConnectionFactory;
// Inject the XA aware ConnectionFactory (uses the alias and injects the same as above)
@Autowired
@Qualifier("xaJmsConnectionFactory")
private ConnectionFactory xaConnectionFactory;
// Inject the non-XA aware ConnectionFactory
@Autowired
@Qualifier("nonXaJmsConnectionFactory")
private ConnectionFactory nonXaConnectionFactory;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/37.-distributed-transactions-with-jta/37.5-mixing-xa-and-non-xa-jms-connections.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
