1.首先搭建springboot,这个很简单
pom.xml引用如下,包括springboot+mybits+rabbitMQ
4.0.0
<groupId>spboot</groupId>
<artifactId>spboot</artifactId>
<version>1.0-SNAPSHOT</version>
<name>springboot-mybatis-demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.1.2</version>
</dependency>
<!-- alibaba的druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>cn.easyproject</groupId>
<artifactId>ojdbc6</artifactId>
<version>12.1.0.2.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>ai.ost</groupId>
<artifactId>fastjson-protobuf</artifactId>
<version>0.1.3</version>
<classifier>sources</classifier>
<type>java-source</type>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- mybatis generator 自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
application.yml
server:
port: 8008
spring:
datasource:
name: test
url: jdbc:oracle:thin:@128.9.7.21:1521:DevGDSYDB
username: activity
password: activity
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: oracle.jdbc.driver.OracleDriver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
application:
name: spirng-boot-rabbitmq
rabbitmq:
host: 127.0.0.1
port: 5672
username: admin
password: 123456
thymeleaf:
content-type:text/html
cache:false
mode :LEGACYHTML5
mybatis:
mapper-locations: classpath:mapping/*.xml
type-aliases-package: com.demo.model
pagehelper:
helperDialect: oracle
reasonable: true
supportMethodsArguments: true
params: count=countSql
2.安装RabbitMQ
安装RabbitMQ之前,需要安装erlang
Erlang官网下载地址:http://www.erlang.org/ ,我是64位机器,就下载otp_win64_21.2.exe
安装完成后,下载RabbitMQ
下载地址:https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.7.13-beta.1
安装即可
安装完成后,配置RabbitMQ,可根据博客https://www.cnblogs.com/ericli-ericli/p/5902270.html
登录RabbitMQ管理界面,需要看新增用户的权限,否则增加队列会被拒绝,新增队列后就可以在java代码里使用该队列了。
3.代码里使用,可根据博客:https://www.cnblogs.com/ityouknow/p/6120544.html
4.spring boot整合rabbitmq的广播配置,参考https://blog.csdn.net/weixiaohuai/article/details/82825658