> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/32.-messaging/32.1.-jms/32.1.4-sending-a-message.md).

# 32.1.4 发送消息

Spring的`JmsTemplate`会被自动配置，你可以将它直接注入到自己的beans中：

```java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
@Component
public class MyBean {
private final JmsTemplate jmsTemplate;
@Autowired
public MyBean(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
// ...
}
```

**注** 你可以使用相同方式注入[JmsMessagingTemplate](https://docs.spring.io/spring/docs/5.0.4.RELEASE/javadoc-api/org/springframework/jms/core/JmsMessagingTemplate.html)。如果定义了一个`DestinationResolver`或`MessageConverter` bean，它将自动关联到自动配置的`JmsTemplate`。
