Configure a Spring JMS application with Spring Boot and annotation support

来源:互联网 发布:lol美服安装包 mac 编辑:程序博客网 时间:2024/04/26 05:48
  1. Introduction

In previous posts we learned how to configure a project using Spring JMS. If you check the article introduction to messaging with Spring JMS , you will notice that it is configured using XML. This article will take advantage of the improvements introduced in Spring 4.1 version, and configure a JMS project using Java config only.

In this example we will also see how easy it can be to configure the project by using Spring Boot .

Before we get started, just note that as usual, you can take a look at the source code of the project used in the examples below.

See the example project at github .这里写链接内容

Sections:

Introduction.The example application.Setting up the project.A simple example with JMS listener.Sending a response to another queue with @SendTo.Conclusion.
  1. The example application

The application uses a Client service to send orders to a JMS queue, where a JMS listener will be registered and handle these orders. Once received, the listener will store the order through the Store service:

We will use the Order class to create orders:

public class Order implements Serializable {
private static final long serialVersionUID = -797586847427389162L;
private final String id;
public Order(String id) {
this.id = id;
}
public String getId() {
return id;
}
}

Before moving on to the first example, we will first explore how the project structure is built.
3. Setting up the project
3.1 Configuring pom.xml

The first thing to do is to define the artifact spring-boot-starter-parent as our parent pom.


org.springframework.boot
spring-boot-starter-parent
1.2.3.RELEASE

This parent basically sets several Maven defaults and provides the dependency management for the main dependencies that we will use, like the Spring version (which is 4.1.6).

It is important to note that this parent pom defines the version of many libraries but it does not add any dependency to our project. So don’t worry about getting libraries you won’t use.

The next step is to set the basic dependencies for Spring Boot:


org.springframework.boot
spring-boot-starter

In addition to the core Spring libraries, this dependency will bring the auto configuration functionality of Spring Boot. This will allow the framework to try to automatically set up the configuration based on the dependencies you add.

Finally, we will add the Spring JMS dependency and the ActiveMQ message broker, leaving the whole pom.xml as follows:

xpadro.spring
jms-boot-javaconfig
0.0.1-SNAPSHOT
jar
JMS Spring Boot Javaconfig

org.springframework.boot
spring-boot-starter-parent
1.2.3.RELEASE



0 0